Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/chromeos/arc/arc_support_host.cc

Issue 2380683008: Fix resource leak on extension window closing. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 const char kOn[] = "on"; 40 const char kOn[] = "on";
41 const char kPage[] = "page"; 41 const char kPage[] = "page";
42 const char kStatus[] = "status"; 42 const char kStatus[] = "status";
43 const char kText[] = "text"; 43 const char kText[] = "text";
44 const char kActionInitialize[] = "initialize"; 44 const char kActionInitialize[] = "initialize";
45 const char kActionSetMetricsMode[] = "setMetricsMode"; 45 const char kActionSetMetricsMode[] = "setMetricsMode";
46 const char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode"; 46 const char kActionBackupAndRestoreMode[] = "setBackupAndRestoreMode";
47 const char kActionLocationServiceMode[] = "setLocationServiceMode"; 47 const char kActionLocationServiceMode[] = "setLocationServiceMode";
48 const char kActionSetWindowBounds[] = "setWindowBounds"; 48 const char kActionSetWindowBounds[] = "setWindowBounds";
49 const char kActionStartLso[] = "startLso"; 49 const char kActionStartLso[] = "startLso";
50 const char kActionCancelAuthCode[] = "cancelAuthCode";
51 const char kActionSetAuthCode[] = "setAuthCode"; 50 const char kActionSetAuthCode[] = "setAuthCode";
52 const char kActionEnableMetrics[] = "enableMetrics"; 51 const char kActionEnableMetrics[] = "enableMetrics";
53 const char kActionSendFeedback[] = "sendFeedback"; 52 const char kActionSendFeedback[] = "sendFeedback";
54 const char kActionSetBackupRestore[] = "setBackupRestore"; 53 const char kActionSetBackupRestore[] = "setBackupRestore";
55 const char kActionSetLocationService[] = "setLocationService"; 54 const char kActionSetLocationService[] = "setLocationService";
56 const char kActionCloseUI[] = "closeUI"; 55 const char kActionCloseWindow[] = "closeWindow";
57 const char kActionShowPage[] = "showPage"; 56 const char kActionShowPage[] = "showPage";
57
58 // Fired when the extension window is closed.
59 const char kActionOnWindowClosed[] = "onWindowClosed";
60
58 } // namespace 61 } // namespace
59 62
60 // static 63 // static
61 const char ArcSupportHost::kHostName[] = "com.google.arc_support"; 64 const char ArcSupportHost::kHostName[] = "com.google.arc_support";
62 65
63 // static 66 // static
64 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; 67 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei";
65 68
66 // static 69 // static
67 const char ArcSupportHost::kStorageId[] = "arc_support"; 70 const char ArcSupportHost::kStorageId[] = "arc_support";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 base::Unretained(this))); 105 base::Unretained(this)));
103 } 106 }
104 107
105 ArcSupportHost::~ArcSupportHost() { 108 ArcSupportHost::~ArcSupportHost() {
106 display::Screen::GetScreen()->RemoveObserver(this); 109 display::Screen::GetScreen()->RemoveObserver(this);
107 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 110 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
108 if (arc_auth_service) 111 if (arc_auth_service)
109 arc_auth_service->RemoveObserver(this); 112 arc_auth_service->RemoveObserver(this);
110 } 113 }
111 114
115 void ArcSupportHost::Close() {
116 if (!client_)
117 return;
118
119 close_requested_ = true;
120 base::DictionaryValue response;
121 response.SetString(kAction, kActionCloseWindow);
122 std::string response_string;
123 base::JSONWriter::Write(response, &response_string);
124 client_->PostMessageFromNativeHost(response_string);
125 }
126
112 void ArcSupportHost::Start(Client* client) { 127 void ArcSupportHost::Start(Client* client) {
113 DCHECK(!client_); 128 DCHECK(!client_);
114 client_ = client; 129 client_ = client;
115 130
116 if (!Initialize()) { 131 if (!Initialize()) {
117 OnOptInUIClose(); 132 Close();
118 return; 133 return;
119 } 134 }
120 135
121 SendMetricsMode(); 136 SendMetricsMode();
122 SendBackupAndRestoreMode(); 137 SendBackupAndRestoreMode();
123 SendLocationServicesMode(); 138 SendLocationServicesMode();
124 139
125 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); 140 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
126 DCHECK(arc_auth_service); 141 DCHECK(arc_auth_service);
127 OnOptInUIShowPage(arc_auth_service->ui_page(), 142 OnOptInUIShowPage(arc_auth_service->ui_page(),
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 292 }
278 293
279 void ArcSupportHost::SendBackupAndRestoreMode() { 294 void ArcSupportHost::SendBackupAndRestoreMode() {
280 SendOptionMode(kActionBackupAndRestoreMode, prefs::kArcBackupRestoreEnabled); 295 SendOptionMode(kActionBackupAndRestoreMode, prefs::kArcBackupRestoreEnabled);
281 } 296 }
282 297
283 void ArcSupportHost::SendLocationServicesMode() { 298 void ArcSupportHost::SendLocationServicesMode() {
284 SendOptionMode(kActionLocationServiceMode, prefs::kArcLocationServiceEnabled); 299 SendOptionMode(kActionLocationServiceMode, prefs::kArcLocationServiceEnabled);
285 } 300 }
286 301
287 void ArcSupportHost::OnOptInUIClose() { 302 void ArcSupportHost::OnOptInUIClose() {
Luis Héctor Chávez 2016/09/30 15:14:14 Given that this and Close() are now equivalent, ca
hidehiko 2016/09/30 15:21:25 I'm planning to remove OnOptInUIClose() as well as
288 if (!client_) 303 Close();
289 return;
290
291 base::DictionaryValue response;
292 response.SetString(kAction, kActionCloseUI);
293 std::string response_string;
294 base::JSONWriter::Write(response, &response_string);
295 client_->PostMessageFromNativeHost(response_string);
296 } 304 }
297 305
298 void ArcSupportHost::OnOptInUIShowPage(arc::ArcAuthService::UIPage page, 306 void ArcSupportHost::OnOptInUIShowPage(arc::ArcAuthService::UIPage page,
299 const base::string16& status) { 307 const base::string16& status) {
300 if (!client_) 308 if (!client_)
301 return; 309 return;
302 310
303 base::DictionaryValue response; 311 base::DictionaryValue response;
304 response.SetString(kAction, kActionShowPage); 312 response.SetString(kAction, kActionShowPage);
305 response.SetInteger(kPage, static_cast<int>(page)); 313 response.SetInteger(kPage, static_cast<int>(page));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 355
348 if (action == kActionStartLso) { 356 if (action == kActionStartLso) {
349 arc_auth_service->StartLso(); 357 arc_auth_service->StartLso();
350 } else if (action == kActionSetAuthCode) { 358 } else if (action == kActionSetAuthCode) {
351 std::string code; 359 std::string code;
352 if (!request->GetString(kCode, &code)) { 360 if (!request->GetString(kCode, &code)) {
353 NOTREACHED(); 361 NOTREACHED();
354 return; 362 return;
355 } 363 }
356 arc_auth_service->SetAuthCodeAndStartArc(code); 364 arc_auth_service->SetAuthCodeAndStartArc(code);
357 } else if (action == kActionCancelAuthCode) { 365 } else if (action == kActionOnWindowClosed) {
358 arc_auth_service->CancelAuthCode(); 366 if (!close_requested_)
367 arc_auth_service->CancelAuthCode();
359 } else if (action == kActionEnableMetrics) { 368 } else if (action == kActionEnableMetrics) {
360 bool is_enabled; 369 bool is_enabled;
361 if (!request->GetBoolean(kEnabled, &is_enabled)) { 370 if (!request->GetBoolean(kEnabled, &is_enabled)) {
362 NOTREACHED(); 371 NOTREACHED();
363 return; 372 return;
364 } 373 }
365 EnableMetrics(is_enabled); 374 EnableMetrics(is_enabled);
366 } else if (action == kActionSendFeedback) { 375 } else if (action == kActionSendFeedback) {
367 chrome::OpenFeedbackDialog(nullptr); 376 chrome::OpenFeedbackDialog(nullptr);
368 } else if (action == kActionSetBackupRestore) { 377 } else if (action == kActionSetBackupRestore) {
(...skipping 12 matching lines...) Expand all
381 EnableLocationService(is_enabled); 390 EnableLocationService(is_enabled);
382 } else { 391 } else {
383 NOTREACHED(); 392 NOTREACHED();
384 } 393 }
385 } 394 }
386 395
387 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() 396 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner()
388 const { 397 const {
389 return base::ThreadTaskRunnerHandle::Get(); 398 return base::ThreadTaskRunnerHandle::Get();
390 } 399 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_support_host.h ('k') | chrome/browser/resources/chromeos/arc_support/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698