Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profile_signin_confirmation_helper.h" | 5 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 13 #include "chrome/browser/common/cancelable_request.h" | 13 #include "chrome/browser/common/cancelable_request.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
| 16 #include "chrome/browser/history/history_backend.h" | 16 #include "chrome/browser/history/history_backend.h" |
| 17 #include "chrome/browser/history/history_db_task.h" | 17 #include "chrome/browser/history/history_db_task.h" |
| 18 #include "chrome/browser/history/history_service.h" | 18 #include "chrome/browser/history/history_service.h" |
| 19 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
| 20 #include "chrome/browser/history/history_types.h" | 20 #include "chrome/browser/history/history_types.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/extensions/sync_helper.h" | 22 #include "chrome/common/extensions/sync_helper.h" |
| 23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 24 #include "extensions/common/extension_set.h" | 24 #include "extensions/common/extension_set.h" |
| 25 #include "ui/gfx/color_utils.h" | 25 #include "ui/gfx/color_utils.h" |
| 26 #include "ui/native_theme/native_theme.h" | 26 #include "ui/native_theme/native_theme.h" |
| 27 | 27 |
| 28 // TODO(dconnelly): change VLOG to DVLOG (crbug.com/240195) | |
| 29 | |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 const int kHistoryEntriesBeforeNewProfilePrompt = 10; | 30 const int kHistoryEntriesBeforeNewProfilePrompt = 10; |
| 33 | 31 |
| 34 // Determines whether a profile has any typed URLs in its history. | 32 // Determines whether a profile has any typed URLs in its history. |
| 35 class HasTypedURLsTask : public history::HistoryDBTask { | 33 class HasTypedURLsTask : public history::HistoryDBTask { |
| 36 public: | 34 public: |
| 37 HasTypedURLsTask(const base::Callback<void(bool)>& cb) | 35 HasTypedURLsTask(const base::Callback<void(bool)>& cb) |
| 38 : has_typed_urls_(false), cb_(cb) { | 36 : has_typed_urls_(false), cb_(cb) { |
| 39 } | 37 } |
| 40 | 38 |
| 41 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 39 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
| 42 history::HistoryDatabase* db) OVERRIDE { | 40 history::HistoryDatabase* db) OVERRIDE { |
| 43 history::URLRows rows; | 41 history::URLRows rows; |
| 44 backend->GetAllTypedURLs(&rows); | 42 backend->GetAllTypedURLs(&rows); |
| 45 if (!rows.empty()) { | 43 if (!rows.empty()) { |
| 46 VLOG(1) << "ProfileSigninConfirmationHelper: profile contains " | 44 DVLOG(1) << "ProfileSigninConfirmationHelper: profile contains " |
| 47 << rows.size() << " typed URLs"; | 45 << rows.size() << " typed URLs"; |
|
Andrew T Wilson (Slow)
2014/01/07 14:58:55
nit: fix indent on line 45 also.
dconnelly
2014/01/07 15:07:15
Done.
| |
| 48 has_typed_urls_ = true; | 46 has_typed_urls_ = true; |
| 49 } | 47 } |
| 50 return true; | 48 return true; |
| 51 } | 49 } |
| 52 | 50 |
| 53 virtual void DoneRunOnMainThread() OVERRIDE { | 51 virtual void DoneRunOnMainThread() OVERRIDE { |
| 54 cb_.Run(has_typed_urls_); | 52 cb_.Run(has_typed_urls_); |
| 55 } | 53 } |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 virtual ~HasTypedURLsTask() {} | 56 virtual ~HasTypedURLsTask() {} |
| 59 bool has_typed_urls_; | 57 bool has_typed_urls_; |
| 60 base::Callback<void(bool)> cb_; | 58 base::Callback<void(bool)> cb_; |
| 61 }; | 59 }; |
| 62 | 60 |
| 63 bool HasBookmarks(Profile* profile) { | 61 bool HasBookmarks(Profile* profile) { |
| 64 BookmarkModel* bookmarks = BookmarkModelFactory::GetForProfile(profile); | 62 BookmarkModel* bookmarks = BookmarkModelFactory::GetForProfile(profile); |
| 65 bool has_bookmarks = bookmarks && bookmarks->HasBookmarks(); | 63 bool has_bookmarks = bookmarks && bookmarks->HasBookmarks(); |
| 66 if (has_bookmarks) | 64 if (has_bookmarks) |
| 67 VLOG(1) << "ProfileSigninConfirmationHelper: profile contains bookmarks"; | 65 DVLOG(1) << "ProfileSigninConfirmationHelper: profile contains bookmarks"; |
| 68 return has_bookmarks; | 66 return has_bookmarks; |
| 69 } | 67 } |
| 70 | 68 |
| 71 // Helper functions for Chrome profile signin. | 69 // Helper functions for Chrome profile signin. |
| 72 class ProfileSigninConfirmationHelper | 70 class ProfileSigninConfirmationHelper |
| 73 : public base::RefCounted<ProfileSigninConfirmationHelper> { | 71 : public base::RefCounted<ProfileSigninConfirmationHelper> { |
| 74 public: | 72 public: |
| 75 ProfileSigninConfirmationHelper( | 73 ProfileSigninConfirmationHelper( |
| 76 Profile* profile, | 74 Profile* profile, |
| 77 const base::Callback<void(bool)>& return_result); | 75 const base::Callback<void(bool)>& return_result); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 } | 118 } |
| 121 | 119 |
| 122 void ProfileSigninConfirmationHelper::OnHistoryQueryResults( | 120 void ProfileSigninConfirmationHelper::OnHistoryQueryResults( |
| 123 size_t max_entries, | 121 size_t max_entries, |
| 124 CancelableRequestProvider::Handle handle, | 122 CancelableRequestProvider::Handle handle, |
| 125 history::QueryResults* results) { | 123 history::QueryResults* results) { |
| 126 history::QueryResults owned_results; | 124 history::QueryResults owned_results; |
| 127 results->Swap(&owned_results); | 125 results->Swap(&owned_results); |
| 128 bool too_much_history = owned_results.size() >= max_entries; | 126 bool too_much_history = owned_results.size() >= max_entries; |
| 129 if (too_much_history) { | 127 if (too_much_history) { |
| 130 VLOG(1) << "ProfileSigninConfirmationHelper: profile contains " | 128 DVLOG(1) << "ProfileSigninConfirmationHelper: profile contains " |
| 131 << owned_results.size() << " history entries"; | 129 << owned_results.size() << " history entries"; |
|
Andrew T Wilson (Slow)
2014/01/07 14:58:55
nit: fix indent on line 129
dconnelly
2014/01/07 15:07:15
Done.
| |
| 132 } | 130 } |
| 133 ReturnResult(too_much_history); | 131 ReturnResult(too_much_history); |
| 134 } | 132 } |
| 135 | 133 |
| 136 void ProfileSigninConfirmationHelper::CheckHasHistory(int max_entries) { | 134 void ProfileSigninConfirmationHelper::CheckHasHistory(int max_entries) { |
| 137 HistoryService* service = | 135 HistoryService* service = |
| 138 HistoryServiceFactory::GetForProfileWithoutCreating(profile_); | 136 HistoryServiceFactory::GetForProfileWithoutCreating(profile_); |
| 139 if (!service) { | 137 if (!service) { |
| 140 ReturnResult(false); | 138 ReturnResult(false); |
| 141 return; | 139 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 SkColor GetSigninConfirmationPromptBarColor(SkAlpha alpha) { | 183 SkColor GetSigninConfirmationPromptBarColor(SkAlpha alpha) { |
| 186 static const SkColor kBackgroundColor = | 184 static const SkColor kBackgroundColor = |
| 187 ui::NativeTheme::instance()->GetSystemColor( | 185 ui::NativeTheme::instance()->GetSystemColor( |
| 188 ui::NativeTheme::kColorId_DialogBackground); | 186 ui::NativeTheme::kColorId_DialogBackground); |
| 189 return color_utils::BlendTowardOppositeLuminance(kBackgroundColor, alpha); | 187 return color_utils::BlendTowardOppositeLuminance(kBackgroundColor, alpha); |
| 190 } | 188 } |
| 191 | 189 |
| 192 bool HasBeenShutdown(Profile* profile) { | 190 bool HasBeenShutdown(Profile* profile) { |
| 193 bool has_been_shutdown = !profile->IsNewProfile(); | 191 bool has_been_shutdown = !profile->IsNewProfile(); |
| 194 if (has_been_shutdown) | 192 if (has_been_shutdown) |
| 195 VLOG(1) << "ProfileSigninConfirmationHelper: profile is not new"; | 193 DVLOG(1) << "ProfileSigninConfirmationHelper: profile is not new"; |
| 196 return has_been_shutdown; | 194 return has_been_shutdown; |
| 197 } | 195 } |
| 198 | 196 |
| 199 bool HasSyncedExtensions(Profile* profile) { | 197 bool HasSyncedExtensions(Profile* profile) { |
| 200 extensions::ExtensionSystem* system = | 198 extensions::ExtensionSystem* system = |
| 201 extensions::ExtensionSystem::Get(profile); | 199 extensions::ExtensionSystem::Get(profile); |
| 202 if (system && system->extension_service()) { | 200 if (system && system->extension_service()) { |
| 203 const extensions::ExtensionSet* extensions = | 201 const extensions::ExtensionSet* extensions = |
| 204 system->extension_service()->extensions(); | 202 system->extension_service()->extensions(); |
| 205 for (extensions::ExtensionSet::const_iterator iter = extensions->begin(); | 203 for (extensions::ExtensionSet::const_iterator iter = extensions->begin(); |
| 206 iter != extensions->end(); ++iter) { | 204 iter != extensions->end(); ++iter) { |
| 207 // The webstore is synced so that it stays put on the new tab | 205 // The webstore is synced so that it stays put on the new tab |
| 208 // page, but since it's installed by default we don't want to | 206 // page, but since it's installed by default we don't want to |
| 209 // consider it when determining if the profile is dirty. | 207 // consider it when determining if the profile is dirty. |
| 210 if (extensions::sync_helper::IsSyncable(iter->get()) && | 208 if (extensions::sync_helper::IsSyncable(iter->get()) && |
| 211 (*iter)->id() != extension_misc::kWebStoreAppId && | 209 (*iter)->id() != extension_misc::kWebStoreAppId && |
| 212 (*iter)->id() != extension_misc::kChromeAppId) { | 210 (*iter)->id() != extension_misc::kChromeAppId) { |
| 213 VLOG(1) << "ProfileSigninConfirmationHelper: " | 211 DVLOG(1) << "ProfileSigninConfirmationHelper: " |
| 214 << "profile contains a synced extension: " << (*iter)->id(); | 212 << "profile contains a synced extension: " << (*iter)->id(); |
|
Andrew T Wilson (Slow)
2014/01/07 14:58:55
nit: fix indent on line 212
dconnelly
2014/01/07 15:07:15
Done.
| |
| 215 return true; | 213 return true; |
| 216 } | 214 } |
| 217 } | 215 } |
| 218 } | 216 } |
| 219 return false; | 217 return false; |
| 220 } | 218 } |
| 221 | 219 |
| 222 void CheckShouldPromptForNewProfile( | 220 void CheckShouldPromptForNewProfile( |
| 223 Profile* profile, | 221 Profile* profile, |
| 224 const base::Callback<void(bool)>& return_result) { | 222 const base::Callback<void(bool)>& return_result) { |
| 225 if (HasBeenShutdown(profile) || | 223 if (HasBeenShutdown(profile) || |
| 226 HasBookmarks(profile) || | 224 HasBookmarks(profile) || |
| 227 HasSyncedExtensions(profile)) { | 225 HasSyncedExtensions(profile)) { |
| 228 return_result.Run(true); | 226 return_result.Run(true); |
| 229 return; | 227 return; |
| 230 } | 228 } |
| 231 // Fire asynchronous queries for profile data. | 229 // Fire asynchronous queries for profile data. |
| 232 scoped_refptr<ProfileSigninConfirmationHelper> helper = | 230 scoped_refptr<ProfileSigninConfirmationHelper> helper = |
| 233 new ProfileSigninConfirmationHelper(profile, return_result); | 231 new ProfileSigninConfirmationHelper(profile, return_result); |
| 234 const int requests = 2; | 232 const int requests = 2; |
| 235 helper->set_pending_requests(requests); | 233 helper->set_pending_requests(requests); |
| 236 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); | 234 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); |
| 237 helper->CheckHasTypedURLs(); | 235 helper->CheckHasTypedURLs(); |
| 238 } | 236 } |
| 239 | 237 |
| 240 } // namespace ui | 238 } // namespace ui |
| OLD | NEW |