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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_sync_observer.cc

Issue 1160073004: chrome/browser/ui: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/sync/one_click_signin_sync_observer.h" 5 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
9 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/signin_promo.h" 12 #include "chrome/browser/signin/signin_promo.h"
11 #include "chrome/browser/sync/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "chrome/browser/sync/profile_sync_service_factory.h" 14 #include "chrome/browser/sync/profile_sync_service_factory.h"
13 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_delegate.h" 16 #include "content/public/browser/web_contents_delegate.h"
15 17
16 namespace { 18 namespace {
17 19
18 void CloseTab(content::WebContents* tab) { 20 void CloseTab(content::WebContents* tab) {
(...skipping 16 matching lines...) Expand all
35 ProfileSyncService* sync_service = GetSyncService(web_contents); 37 ProfileSyncService* sync_service = GetSyncService(web_contents);
36 if (sync_service) { 38 if (sync_service) {
37 sync_service->AddObserver(this); 39 sync_service->AddObserver(this);
38 } else { 40 } else {
39 LoadContinueUrl(); 41 LoadContinueUrl();
40 // Post a task rather than calling |delete this| here, so that the 42 // Post a task rather than calling |delete this| here, so that the
41 // destructor is not called directly from the constructor. Note that it's 43 // destructor is not called directly from the constructor. Note that it's
42 // important to pass a weak pointer rather than base::Unretained(this) 44 // important to pass a weak pointer rather than base::Unretained(this)
43 // because it's possible for e.g. WebContentsDestroyed() to be called 45 // because it's possible for e.g. WebContentsDestroyed() to be called
44 // before this task has a chance to run. 46 // before this task has a chance to run.
45 base::MessageLoop::current()->PostTask( 47 base::ThreadTaskRunnerHandle::Get()->PostTask(
46 FROM_HERE, 48 FROM_HERE, base::Bind(&OneClickSigninSyncObserver::DeleteObserver,
47 base::Bind(&OneClickSigninSyncObserver::DeleteObserver, 49 weak_ptr_factory_.GetWeakPtr()));
48 weak_ptr_factory_.GetWeakPtr()));
49 } 50 }
50 } 51 }
51 52
52 OneClickSigninSyncObserver::~OneClickSigninSyncObserver() {} 53 OneClickSigninSyncObserver::~OneClickSigninSyncObserver() {}
53 54
54 void OneClickSigninSyncObserver::WebContentsDestroyed() { 55 void OneClickSigninSyncObserver::WebContentsDestroyed() {
55 ProfileSyncService* sync_service = GetSyncService(web_contents()); 56 ProfileSyncService* sync_service = GetSyncService(web_contents());
56 if (sync_service) 57 if (sync_service)
57 sync_service->RemoveObserver(this); 58 sync_service->RemoveObserver(this);
58 59
59 delete this; 60 delete this;
60 } 61 }
61 62
62 void OneClickSigninSyncObserver::OnStateChanged() { 63 void OneClickSigninSyncObserver::OnStateChanged() {
63 ProfileSyncService* sync_service = GetSyncService(web_contents()); 64 ProfileSyncService* sync_service = GetSyncService(web_contents());
64 65
65 // At this point, the sign-in process is complete, and control has been handed 66 // At this point, the sign-in process is complete, and control has been handed
66 // back to the sync engine. Close the gaia sign in tab if the |continue_url_| 67 // back to the sync engine. Close the gaia sign in tab if the |continue_url_|
67 // contains the |auto_close| parameter. Otherwise, wait for sync setup to 68 // contains the |auto_close| parameter. Otherwise, wait for sync setup to
68 // complete and then navigate to the |continue_url_|. 69 // complete and then navigate to the |continue_url_|.
69 if (signin::IsAutoCloseEnabledInURL(continue_url_)) { 70 if (signin::IsAutoCloseEnabledInURL(continue_url_)) {
70 // Close the Gaia sign-in tab via a task to make sure we aren't in the 71 // Close the Gaia sign-in tab via a task to make sure we aren't in the
71 // middle of any WebUI handler code. 72 // middle of any WebUI handler code.
72 base::MessageLoop::current()->PostTask( 73 base::ThreadTaskRunnerHandle::Get()->PostTask(
73 FROM_HERE, 74 FROM_HERE, base::Bind(&CloseTab, base::Unretained(web_contents())));
74 base::Bind(&CloseTab, base::Unretained(web_contents())));
75 } else { 75 } else {
76 if (sync_service->FirstSetupInProgress()) { 76 if (sync_service->FirstSetupInProgress()) {
77 // Sync setup has not completed yet. Wait for it to complete. 77 // Sync setup has not completed yet. Wait for it to complete.
78 return; 78 return;
79 } 79 }
80 80
81 if (sync_service->IsSyncActive() && 81 if (sync_service->IsSyncActive() &&
82 signin::GetSourceForPromoURL(continue_url_) 82 signin::GetSourceForPromoURL(continue_url_)
83 != signin_metrics::SOURCE_SETTINGS) { 83 != signin_metrics::SOURCE_SETTINGS) {
84 // TODO(isherman): Having multiple settings pages open can cause issues 84 // TODO(isherman): Having multiple settings pages open can cause issues
(...skipping 20 matching lines...) Expand all
105 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 105 Profile::FromBrowserContext(web_contents->GetBrowserContext());
106 return ProfileSyncServiceFactory::GetForProfile(profile); 106 return ProfileSyncServiceFactory::GetForProfile(profile);
107 } 107 }
108 108
109 // static 109 // static
110 void OneClickSigninSyncObserver::DeleteObserver( 110 void OneClickSigninSyncObserver::DeleteObserver(
111 base::WeakPtr<OneClickSigninSyncObserver> observer) { 111 base::WeakPtr<OneClickSigninSyncObserver> observer) {
112 if (observer) 112 if (observer)
113 delete observer.get(); 113 delete observer.get();
114 } 114 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/default_browser_prompt.cc ('k') | chrome/browser/ui/tab_modal_confirm_dialog_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698