This commit is contained in:
Cheng Zhao 2016-04-18 13:59:15 +09:00
parent 8d08c3241d
commit 0bf1e56156
3 changed files with 13 additions and 18 deletions

View file

@ -23,12 +23,13 @@
#include "atom/common/native_mate_converters/net_converter.h" #include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/guid.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "brightray/browser/net/devtools_network_conditions.h" #include "brightray/browser/net/devtools_network_conditions.h"
#include "brightray/browser/net/devtools_network_controller.h" #include "brightray/browser/net/devtools_network_controller_handle.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
@ -288,7 +289,8 @@ void ClearHostResolverCacheInIO(
} // namespace } // namespace
Session::Session(AtomBrowserContext* browser_context) Session::Session(AtomBrowserContext* browser_context)
: browser_context_(browser_context) { : devtools_network_emulation_client_id_(base::GenerateGUID()),
browser_context_(browser_context) {
AttachAsUserData(browser_context); AttachAsUserData(browser_context);
// Observe DownloadManger to get download notifications. // Observe DownloadManger to get download notifications.
@ -381,25 +383,15 @@ void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
download_throughput, download_throughput,
upload_throughput)); upload_throughput));
} }
auto controller = browser_context_->GetDevToolsNetworkController();
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, browser_context_->network_controller_handle()->SetNetworkState(
base::Bind(&brightray::DevToolsNetworkController::SetNetworkState, devtools_network_emulation_client_id_, std::move(conditions));
base::Unretained(controller),
std::string(),
base::Passed(&conditions)));
} }
void Session::DisableNetworkEmulation() { void Session::DisableNetworkEmulation() {
scoped_ptr<brightray::DevToolsNetworkConditions> conditions( scoped_ptr<brightray::DevToolsNetworkConditions> conditions;
new brightray::DevToolsNetworkConditions(false)); browser_context_->network_controller_handle()->SetNetworkState(
auto controller = browser_context_->GetDevToolsNetworkController(); devtools_network_emulation_client_id_, std::move(conditions));
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&brightray::DevToolsNetworkController::SetNetworkState,
base::Unretained(controller),
std::string(),
base::Passed(&conditions)));
} }
void Session::SetCertVerifyProc(v8::Local<v8::Value> val, void Session::SetCertVerifyProc(v8::Local<v8::Value> val,

View file

@ -86,6 +86,9 @@ class Session: public mate::TrackableObject<Session>,
v8::Global<v8::Value> cookies_; v8::Global<v8::Value> cookies_;
v8::Global<v8::Value> web_request_; v8::Global<v8::Value> web_request_;
// The X-DevTools-Emulate-Network-Conditions-Client-Id.
std::string devtools_network_emulation_client_id_;
scoped_refptr<AtomBrowserContext> browser_context_; scoped_refptr<AtomBrowserContext> browser_context_;
DISALLOW_COPY_AND_ASSIGN(Session); DISALLOW_COPY_AND_ASSIGN(Session);

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit 79b80e83f4a64790e51ad2fc44b0a56bdb3d7ef3 Subproject commit bc9c496a6185e37e792c10bfc5b49ea779b27cd3