OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 5 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/common/system/chromeos/devicetype_utils.h" | 9 #include "ash/common/system/chromeos/devicetype_utils.h" |
10 #include "base/i18n/timezone.h" | 10 #include "base/i18n/timezone.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"}; | 67 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"}; |
68 | 68 |
69 // static | 69 // static |
70 std::unique_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { | 70 std::unique_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { |
71 return std::unique_ptr<NativeMessageHost>(new ArcSupportHost()); | 71 return std::unique_ptr<NativeMessageHost>(new ArcSupportHost()); |
72 } | 72 } |
73 | 73 |
74 ArcSupportHost::ArcSupportHost() { | 74 ArcSupportHost::ArcSupportHost() { |
75 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 75 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
76 DCHECK(arc_auth_service); | 76 DCHECK(arc_auth_service); |
| 77 |
| 78 if (!arc_auth_service->IsAllowed()) |
| 79 return; |
| 80 |
77 arc_auth_service->AddObserver(this); | 81 arc_auth_service->AddObserver(this); |
78 display::Screen::GetScreen()->AddObserver(this); | 82 display::Screen::GetScreen()->AddObserver(this); |
79 | 83 |
80 pref_change_registrar_.Init(g_browser_process->local_state()); | 84 pref_change_registrar_.Init(g_browser_process->local_state()); |
81 pref_change_registrar_.Add( | 85 pref_change_registrar_.Add( |
82 metrics::prefs::kMetricsReportingEnabled, | 86 metrics::prefs::kMetricsReportingEnabled, |
83 base::Bind(&ArcSupportHost::OnMetricsPreferenceChanged, | 87 base::Bind(&ArcSupportHost::OnMetricsPreferenceChanged, |
84 base::Unretained(this))); | 88 base::Unretained(this))); |
85 } | 89 } |
86 | 90 |
87 ArcSupportHost::~ArcSupportHost() { | 91 ArcSupportHost::~ArcSupportHost() { |
88 display::Screen::GetScreen()->RemoveObserver(this); | 92 display::Screen::GetScreen()->RemoveObserver(this); |
89 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 93 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
90 if (arc_auth_service) | 94 if (arc_auth_service) |
91 arc_auth_service->RemoveObserver(this); | 95 arc_auth_service->RemoveObserver(this); |
92 } | 96 } |
93 | 97 |
94 void ArcSupportHost::Start(Client* client) { | 98 void ArcSupportHost::Start(Client* client) { |
95 DCHECK(!client_); | 99 DCHECK(!client_); |
96 client_ = client; | 100 client_ = client; |
97 | 101 |
98 Initialize(); | 102 if (!Initialize()) { |
| 103 OnOptInUIClose(); |
| 104 return; |
| 105 } |
| 106 |
99 SendMetricsMode(); | 107 SendMetricsMode(); |
100 | 108 |
101 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 109 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
102 DCHECK(arc_auth_service); | 110 DCHECK(arc_auth_service); |
103 OnOptInUIShowPage(arc_auth_service->ui_page(), | 111 OnOptInUIShowPage(arc_auth_service->ui_page(), |
104 arc_auth_service->ui_page_status()); | 112 arc_auth_service->ui_page_status()); |
105 } | 113 } |
106 | 114 |
107 void ArcSupportHost::Initialize() { | 115 bool ArcSupportHost::Initialize() { |
108 DCHECK(client_); | 116 DCHECK(client_); |
| 117 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 118 if (!arc_auth_service->IsAllowed()) |
| 119 return false; |
| 120 |
109 std::unique_ptr<base::DictionaryValue> loadtime_data( | 121 std::unique_ptr<base::DictionaryValue> loadtime_data( |
110 new base::DictionaryValue()); | 122 new base::DictionaryValue()); |
111 base::string16 device_name = ash::GetChromeOSDeviceName(); | 123 base::string16 device_name = ash::GetChromeOSDeviceName(); |
112 loadtime_data->SetString( | 124 loadtime_data->SetString( |
113 "greetingHeader", | 125 "greetingHeader", |
114 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); | 126 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); |
115 loadtime_data->SetString("greetingDescription", | 127 loadtime_data->SetString("greetingDescription", |
116 l10n_util::GetStringFUTF16( | 128 l10n_util::GetStringFUTF16( |
117 IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, device_name)); | 129 IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, device_name)); |
118 loadtime_data->SetString( | 130 loadtime_data->SetString( |
(...skipping 24 matching lines...) Expand all Loading... |
143 "textBackupRestore", | 155 "textBackupRestore", |
144 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE)); | 156 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BACKUP_RESTORE)); |
145 loadtime_data->SetString( | 157 loadtime_data->SetString( |
146 "serverError", | 158 "serverError", |
147 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 159 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
148 | 160 |
149 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 161 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
150 const std::string& country_code = base::CountryCodeForCurrentTimezone(); | 162 const std::string& country_code = base::CountryCodeForCurrentTimezone(); |
151 loadtime_data->SetString("countryCode", country_code); | 163 loadtime_data->SetString("countryCode", country_code); |
152 | 164 |
153 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | |
154 | |
155 loadtime_data->SetBoolean(kBackupRestoreEnabled, | 165 loadtime_data->SetBoolean(kBackupRestoreEnabled, |
156 arc_auth_service->profile()->GetPrefs()->GetBoolean( | 166 arc_auth_service->profile()->GetPrefs()->GetBoolean( |
157 prefs::kArcBackupRestoreEnabled)); | 167 prefs::kArcBackupRestoreEnabled)); |
158 | 168 |
159 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); | 169 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); |
160 DCHECK(arc_auth_service); | 170 DCHECK(arc_auth_service); |
161 const std::string device_id = user_manager::known_user::GetDeviceId( | 171 const std::string device_id = user_manager::known_user::GetDeviceId( |
162 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); | 172 multi_user_util::GetAccountIdFromProfile(arc_auth_service->profile())); |
163 DCHECK(!device_id.empty()); | 173 DCHECK(!device_id.empty()); |
164 | 174 |
165 base::DictionaryValue request; | 175 base::DictionaryValue request; |
166 std::string request_string; | 176 std::string request_string; |
167 request.SetString(kAction, kActionInitialize); | 177 request.SetString(kAction, kActionInitialize); |
168 request.Set(kData, std::move(loadtime_data)); | 178 request.Set(kData, std::move(loadtime_data)); |
169 request.SetString(kDeviceId, device_id); | 179 request.SetString(kDeviceId, device_id); |
170 base::JSONWriter::Write(request, &request_string); | 180 base::JSONWriter::Write(request, &request_string); |
171 client_->PostMessageFromNativeHost(request_string); | 181 client_->PostMessageFromNativeHost(request_string); |
| 182 |
| 183 return true; |
172 } | 184 } |
173 | 185 |
174 void ArcSupportHost::OnDisplayAdded(const display::Display& new_display) {} | 186 void ArcSupportHost::OnDisplayAdded(const display::Display& new_display) {} |
175 | 187 |
176 void ArcSupportHost::OnDisplayRemoved(const display::Display& old_display) {} | 188 void ArcSupportHost::OnDisplayRemoved(const display::Display& old_display) {} |
177 | 189 |
178 void ArcSupportHost::OnDisplayMetricsChanged(const display::Display& display, | 190 void ArcSupportHost::OnDisplayMetricsChanged(const display::Display& display, |
179 uint32_t changed_metrics) { | 191 uint32_t changed_metrics) { |
180 base::DictionaryValue request; | 192 base::DictionaryValue request; |
181 std::string request_string; | 193 std::string request_string; |
182 request.SetString(kAction, kActionSetWindowBounds); | 194 request.SetString(kAction, kActionSetWindowBounds); |
183 base::JSONWriter::Write(request, &request_string); | 195 base::JSONWriter::Write(request, &request_string); |
184 client_->PostMessageFromNativeHost(request_string); | 196 client_->PostMessageFromNativeHost(request_string); |
185 } | 197 } |
186 | 198 |
187 void ArcSupportHost::OnMetricsPreferenceChanged() { | 199 void ArcSupportHost::OnMetricsPreferenceChanged() { |
188 SendMetricsMode(); | 200 SendMetricsMode(); |
189 } | 201 } |
190 | 202 |
191 void ArcSupportHost::SendMetricsMode() { | 203 void ArcSupportHost::SendMetricsMode() { |
192 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 204 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
193 DCHECK(arc_auth_service); | 205 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); |
194 const Profile* profile = arc_auth_service->profile(); | 206 const Profile* profile = arc_auth_service->profile(); |
195 | 207 |
196 const bool metrics_managed = IsMetricsReportingPolicyManaged(); | 208 const bool metrics_managed = IsMetricsReportingPolicyManaged(); |
197 const bool owner_profile = | 209 const bool owner_profile = |
198 profile && chromeos::ProfileHelper::IsOwnerProfile(profile); | 210 profile && chromeos::ProfileHelper::IsOwnerProfile(profile); |
199 const bool metrics_on = | 211 const bool metrics_on = |
200 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 212 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
201 | 213 |
202 int message_id; | 214 int message_id; |
203 if (metrics_managed || !owner_profile) { | 215 if (metrics_managed || !owner_profile) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 std::string response_string; | 254 std::string response_string; |
243 base::JSONWriter::Write(response, &response_string); | 255 base::JSONWriter::Write(response, &response_string); |
244 client_->PostMessageFromNativeHost(response_string); | 256 client_->PostMessageFromNativeHost(response_string); |
245 } | 257 } |
246 | 258 |
247 void ArcSupportHost::EnableMetrics(bool is_enabled) { | 259 void ArcSupportHost::EnableMetrics(bool is_enabled) { |
248 InitiateMetricsReportingChange(is_enabled, OnMetricsReportingCallbackType()); | 260 InitiateMetricsReportingChange(is_enabled, OnMetricsReportingCallbackType()); |
249 } | 261 } |
250 | 262 |
251 void ArcSupportHost::EnableBackupRestore(bool is_enabled) { | 263 void ArcSupportHost::EnableBackupRestore(bool is_enabled) { |
252 PrefService* pref_service = arc::ArcAuthService::Get()->profile()->GetPrefs(); | 264 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 265 DCHECK(arc_auth_service && arc_auth_service->IsAllowed()); |
| 266 PrefService* pref_service = arc_auth_service->profile()->GetPrefs(); |
253 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled); | 267 pref_service->SetBoolean(prefs::kArcBackupRestoreEnabled, is_enabled); |
254 } | 268 } |
255 | 269 |
256 void ArcSupportHost::OnMessage(const std::string& request_string) { | 270 void ArcSupportHost::OnMessage(const std::string& request_string) { |
257 std::unique_ptr<base::Value> request_value = | 271 std::unique_ptr<base::Value> request_value = |
258 base::JSONReader::Read(request_string); | 272 base::JSONReader::Read(request_string); |
259 base::DictionaryValue* request; | 273 base::DictionaryValue* request; |
260 if (!request_value || !request_value->GetAsDictionary(&request)) { | 274 if (!request_value || !request_value->GetAsDictionary(&request)) { |
261 NOTREACHED(); | 275 NOTREACHED(); |
262 return; | 276 return; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 EnableBackupRestore(is_enabled); | 314 EnableBackupRestore(is_enabled); |
301 } else { | 315 } else { |
302 NOTREACHED(); | 316 NOTREACHED(); |
303 } | 317 } |
304 } | 318 } |
305 | 319 |
306 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() | 320 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() |
307 const { | 321 const { |
308 return base::ThreadTaskRunnerHandle::Get(); | 322 return base::ThreadTaskRunnerHandle::Get(); |
309 } | 323 } |
OLD | NEW |