前言
做实验,想向chromium工程的类中加入一个成员变量,结果出现如下编译错误:
WeakPtrFactory members which refer to their outer class must be the last member in the outer class definition
没想到是啥错误,其实错误提示也很明显。
后来看看类有没有WeakPtrFactory类型的成员变量,真有啊,将自己定义的新变量,放在他上面就行。说明,如果类中有WeakPtrFactory类型的成员变量,必须是类中最后一个成员变量. autoninja检查的挺严格的。
实验
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_
#include <string>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/download/public/background_service/logger.h"
#include "content/public/browser/web_ui_message_handler.h"
// Z:\chromium\src\url\gurl.h
#include "url/gurl.h"
namespace download {
class DownloadService;
}
namespace download_internals {
// Class acting as a controller of the chrome://download-internals WebUI.
class DownloadInternalsUIMessageHandler : public content::WebUIMessageHandler,
public download::Logger::Observer {
public:
DownloadInternalsUIMessageHandler();
~DownloadInternalsUIMessageHandler() override;
// content::WebUIMessageHandler implementation.
void RegisterMessages() override;
// download::Logger::Observer implementation.
void OnServiceStatusChanged(const base::Value& service_status) override;
void OnServiceDownloadsAvailable(
const base::Value& service_downloads) override;
void OnServiceDownloadChanged(const base::Value& service_download) override;
void OnServiceDownloadFailed(const base::Value& service_download) override;
void OnServiceRequestMade(const base::Value& service_request) override;
private:
// Get the current DownloadService and sub component statuses.
void HandleGetServiceStatus(const base::ListValue* args);
void HandleGetServiceDownloads(const base::ListValue* args);
// Starts a background download.
void HandleStartDownload(const base::ListValue* args);
void HandleStartDownload_url(GURL& url);
bool get_string_value_by_key_from_value(const base::Value& value, const char* psz_key, std::string& str_value);
bool get_double_value_by_key_from_value(const base::Value& value, const char* psz_key, double& f_value);
private:
download::DownloadService* download_service_;
// base::WeakPtrFactory<>类型的成员变量必须是本类的最后一个成员变量
// 成员变量如果是类, 必须加在base::WeakPtrFactory类型成员变量的上面,否则报错如下
// WeakPtrFactory members which refer to their outer class must be the last member in the outer class definition
std::string m_str_url_by_js_first; // 保存第一次js发来的url
base::WeakPtrFactory<DownloadInternalsUIMessageHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DownloadInternalsUIMessageHandler);
};
} // namespace download_internals
#endif // CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_