1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// Copyright 2014 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.
#include "chromecast/shell/browser/cast_browser_main_parts.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_registry_simple.h"
#include "chromecast/common/chromecast_config.h"
#include "chromecast/metrics/cast_metrics_service_client.h"
#include "chromecast/net/network_change_notifier_cast.h"
#include "chromecast/net/network_change_notifier_factory_cast.h"
#include "chromecast/service/cast_service.h"
#include "chromecast/shell/browser/cast_browser_context.h"
#include "chromecast/shell/browser/cast_browser_process.h"
#include "chromecast/shell/browser/devtools/remote_debugging_server.h"
#include "chromecast/shell/browser/url_request_context_factory.h"
#include "chromecast/shell/browser/webui/webui_cast.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "media/base/media_switches.h"
#if defined(OS_ANDROID)
#include "net/android/network_change_notifier_factory_android.h"
#endif // defined(OS_ANDROID)
namespace chromecast {
namespace shell {
namespace {
struct DefaultCommandLineSwitch {
const char* const switch_name;
const char* const switch_value;
};
DefaultCommandLineSwitch g_default_switches[] = {
#if defined(OS_ANDROID)
{ switches::kMediaDrmEnableNonCompositing, ""},
{ switches::kEnableOverlayFullscreenVideo, ""},
{ switches::kDisableInfobarForProtectedMediaIdentifier, ""},
{ switches::kDisableGestureRequirementForMediaPlayback, ""},
#endif
{ switches::kDisableApplicationCache, "" },
{ switches::kDisablePlugins, "" },
// Always enable HTMLMediaElement logs.
{ switches::kBlinkPlatformLogChannels, "Media"},
{ NULL, NULL }, // Termination
};
void AddDefaultCommandLineSwitches(CommandLine* command_line) {
int i = 0;
while (g_default_switches[i].switch_name != NULL) {
command_line->AppendSwitchASCII(
std::string(g_default_switches[i].switch_name),
std::string(g_default_switches[i].switch_value));
++i;
}
}
} // namespace
CastBrowserMainParts::CastBrowserMainParts(
const content::MainFunctionParams& parameters,
URLRequestContextFactory* url_request_context_factory)
: BrowserMainParts(),
cast_browser_process_(new CastBrowserProcess()),
parameters_(parameters),
url_request_context_factory_(url_request_context_factory) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
AddDefaultCommandLineSwitches(command_line);
}
CastBrowserMainParts::~CastBrowserMainParts() {
}
void CastBrowserMainParts::PreMainMessageLoopStart() {
#if defined(OS_ANDROID)
net::NetworkChangeNotifier::SetFactory(
new net::NetworkChangeNotifierFactoryAndroid());
#else
net::NetworkChangeNotifier::SetFactory(
new NetworkChangeNotifierFactoryCast());
#endif // defined(OS_ANDROID)
}
void CastBrowserMainParts::PostMainMessageLoopStart() {
#if defined(OS_ANDROID)
base::MessageLoopForUI::current()->Start();
#endif // defined(OS_ANDROID)
}
int CastBrowserMainParts::PreCreateThreads() {
ChromecastConfig::Create(new PrefRegistrySimple());
return 0;
}
void CastBrowserMainParts::PreMainMessageLoopRun() {
url_request_context_factory_->InitializeOnUIThread();
cast_browser_process_->SetBrowserContext(
new CastBrowserContext(url_request_context_factory_));
cast_browser_process_->SetMetricsServiceClient(
metrics::CastMetricsServiceClient::Create(
content::BrowserThread::GetBlockingPool(),
ChromecastConfig::GetInstance()->pref_service(),
cast_browser_process_->browser_context()->GetRequestContext()));
cast_browser_process_->SetRemoteDebuggingServer(new RemoteDebuggingServer());
InitializeWebUI();
cast_browser_process_->SetCastService(CastService::Create(
cast_browser_process_->browser_context(),
url_request_context_factory_->GetSystemGetter(),
url_request_context_factory_->app_network_delegate()));
// Initializing network delegates must happen after Cast service is created.
url_request_context_factory_->InitializeNetworkDelegates();
cast_browser_process_->cast_service()->Start();
}
bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) {
// If parameters_.ui_task is not NULL, we are running browser tests. In this
// case, the browser's main message loop will not run.
if (parameters_.ui_task) {
parameters_.ui_task->Run();
} else {
base::MessageLoopForUI::current()->Run();
}
return true;
}
void CastBrowserMainParts::PostMainMessageLoopRun() {
cast_browser_process_->cast_service()->Stop();
cast_browser_process_.reset();
}
} // namespace shell
} // namespace chromecast
|