| OLD | NEW |
| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 | 28 |
| 29 OneClickSigninSyncObserver::OneClickSigninSyncObserver( | 29 OneClickSigninSyncObserver::OneClickSigninSyncObserver( |
| 30 content::WebContents* web_contents, | 30 content::WebContents* web_contents, |
| 31 const GURL& continue_url) | 31 const GURL& continue_url) |
| 32 : content::WebContentsObserver(web_contents), | 32 : content::WebContentsObserver(web_contents), |
| 33 continue_url_(continue_url), | 33 continue_url_(continue_url), |
| 34 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 35 DCHECK(!continue_url_.is_empty()); | 35 DCHECK(!continue_url_.is_empty()); |
| 36 | 36 |
| 37 ProfileSyncService* sync_service = GetSyncService(web_contents); | 37 browser_sync::ProfileSyncService* sync_service = GetSyncService(web_contents); |
| 38 if (sync_service) { | 38 if (sync_service) { |
| 39 sync_service->AddObserver(this); | 39 sync_service->AddObserver(this); |
| 40 } else { | 40 } else { |
| 41 LoadContinueUrl(); | 41 LoadContinueUrl(); |
| 42 // 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 |
| 43 // 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 |
| 44 // important to pass a weak pointer rather than base::Unretained(this) | 44 // important to pass a weak pointer rather than base::Unretained(this) |
| 45 // because it's possible for e.g. WebContentsDestroyed() to be called | 45 // because it's possible for e.g. WebContentsDestroyed() to be called |
| 46 // before this task has a chance to run. | 46 // before this task has a chance to run. |
| 47 base::ThreadTaskRunnerHandle::Get()->PostTask( | 47 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 48 FROM_HERE, base::Bind(&OneClickSigninSyncObserver::DeleteObserver, | 48 FROM_HERE, base::Bind(&OneClickSigninSyncObserver::DeleteObserver, |
| 49 weak_ptr_factory_.GetWeakPtr())); | 49 weak_ptr_factory_.GetWeakPtr())); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 OneClickSigninSyncObserver::~OneClickSigninSyncObserver() {} | 53 OneClickSigninSyncObserver::~OneClickSigninSyncObserver() {} |
| 54 | 54 |
| 55 void OneClickSigninSyncObserver::WebContentsDestroyed() { | 55 void OneClickSigninSyncObserver::WebContentsDestroyed() { |
| 56 ProfileSyncService* sync_service = GetSyncService(web_contents()); | 56 browser_sync::ProfileSyncService* sync_service = |
| 57 GetSyncService(web_contents()); |
| 57 if (sync_service) | 58 if (sync_service) |
| 58 sync_service->RemoveObserver(this); | 59 sync_service->RemoveObserver(this); |
| 59 | 60 |
| 60 delete this; | 61 delete this; |
| 61 } | 62 } |
| 62 | 63 |
| 63 void OneClickSigninSyncObserver::OnStateChanged() { | 64 void OneClickSigninSyncObserver::OnStateChanged() { |
| 64 ProfileSyncService* sync_service = GetSyncService(web_contents()); | 65 browser_sync::ProfileSyncService* sync_service = |
| 66 GetSyncService(web_contents()); |
| 65 | 67 |
| 66 // At this point, the sign-in process is complete, and control has been handed | 68 // At this point, the sign-in process is complete, and control has been handed |
| 67 // back to the sync engine. Close the gaia sign in tab if the |continue_url_| | 69 // back to the sync engine. Close the gaia sign in tab if the |continue_url_| |
| 68 // contains the |auto_close| parameter. Otherwise, wait for sync setup to | 70 // contains the |auto_close| parameter. Otherwise, wait for sync setup to |
| 69 // complete and then navigate to the |continue_url_|. | 71 // complete and then navigate to the |continue_url_|. |
| 70 if (signin::IsAutoCloseEnabledInURL(continue_url_)) { | 72 if (signin::IsAutoCloseEnabledInURL(continue_url_)) { |
| 71 // Close the Gaia sign-in tab via a task to make sure we aren't in the | 73 // Close the Gaia sign-in tab via a task to make sure we aren't in the |
| 72 // middle of any WebUI handler code. | 74 // middle of any WebUI handler code. |
| 73 base::ThreadTaskRunnerHandle::Get()->PostTask( | 75 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 74 FROM_HERE, base::Bind(&CloseTab, base::Unretained(web_contents()))); | 76 FROM_HERE, base::Bind(&CloseTab, base::Unretained(web_contents()))); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 92 } | 94 } |
| 93 | 95 |
| 94 void OneClickSigninSyncObserver::LoadContinueUrl() { | 96 void OneClickSigninSyncObserver::LoadContinueUrl() { |
| 95 web_contents()->GetController().LoadURL( | 97 web_contents()->GetController().LoadURL( |
| 96 continue_url_, | 98 continue_url_, |
| 97 content::Referrer(), | 99 content::Referrer(), |
| 98 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 100 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 99 std::string()); | 101 std::string()); |
| 100 } | 102 } |
| 101 | 103 |
| 102 ProfileSyncService* OneClickSigninSyncObserver::GetSyncService( | 104 browser_sync::ProfileSyncService* OneClickSigninSyncObserver::GetSyncService( |
| 103 content::WebContents* web_contents) { | 105 content::WebContents* web_contents) { |
| 104 Profile* profile = | 106 Profile* profile = |
| 105 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 107 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 106 return ProfileSyncServiceFactory::GetForProfile(profile); | 108 return ProfileSyncServiceFactory::GetForProfile(profile); |
| 107 } | 109 } |
| 108 | 110 |
| 109 // static | 111 // static |
| 110 void OneClickSigninSyncObserver::DeleteObserver( | 112 void OneClickSigninSyncObserver::DeleteObserver( |
| 111 base::WeakPtr<OneClickSigninSyncObserver> observer) { | 113 base::WeakPtr<OneClickSigninSyncObserver> observer) { |
| 112 if (observer) | 114 if (observer) |
| 113 delete observer.get(); | 115 delete observer.get(); |
| 114 } | 116 } |
| OLD | NEW |