| 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/string16.h" | 10 #include "base/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/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_set.h" | 23 #include "chrome/common/extensions/extension_set.h" |
| 24 #include "ui/gfx/color_utils.h" |
| 25 #include "ui/native_theme/native_theme.h" |
| 24 | 26 |
| 25 // TODO(dconnelly): change VLOG to DVLOG (crbug.com/240195) | 27 // TODO(dconnelly): change VLOG to DVLOG (crbug.com/240195) |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 const int kHistoryEntriesBeforeNewProfilePrompt = 10; | 31 const int kHistoryEntriesBeforeNewProfilePrompt = 10; |
| 30 | 32 |
| 31 // Determines whether a profile has any typed URLs in its history. | 33 // Determines whether a profile has any typed URLs in its history. |
| 32 class HasTypedURLsTask : public history::HistoryDBTask { | 34 class HasTypedURLsTask : public history::HistoryDBTask { |
| 33 public: | 35 public: |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 result_returned_ = true; | 195 result_returned_ = true; |
| 194 request_consumer_.CancelAllRequests(); | 196 request_consumer_.CancelAllRequests(); |
| 195 return_result_.Run(result); | 197 return_result_.Run(result); |
| 196 } | 198 } |
| 197 } | 199 } |
| 198 | 200 |
| 199 } // namespace | 201 } // namespace |
| 200 | 202 |
| 201 namespace ui { | 203 namespace ui { |
| 202 | 204 |
| 205 SkColor GetSigninConfirmationPromptBarColor(SkAlpha alpha) { |
| 206 static const SkColor kBackgroundColor = |
| 207 ui::NativeTheme::instance()->GetSystemColor( |
| 208 ui::NativeTheme::kColorId_DialogBackground); |
| 209 unsigned char background_luminance = |
| 210 color_utils::GetLuminanceForColor(kBackgroundColor); |
| 211 const SkColor blend_color = |
| 212 background_luminance < 128 ? SK_ColorWHITE : SK_ColorBLACK; |
| 213 return color_utils::AlphaBlend(blend_color, kBackgroundColor, alpha); |
| 214 } |
| 215 |
| 203 bool HasBeenShutdown(Profile* profile) { | 216 bool HasBeenShutdown(Profile* profile) { |
| 204 bool has_been_shutdown = !profile->IsNewProfile(); | 217 bool has_been_shutdown = !profile->IsNewProfile(); |
| 205 if (has_been_shutdown) | 218 if (has_been_shutdown) |
| 206 VLOG(1) << "ProfileSigninConfirmationHelper: profile is not new"; | 219 VLOG(1) << "ProfileSigninConfirmationHelper: profile is not new"; |
| 207 return has_been_shutdown; | 220 return has_been_shutdown; |
| 208 } | 221 } |
| 209 | 222 |
| 210 void CheckShouldPromptForNewProfile( | 223 void CheckShouldPromptForNewProfile( |
| 211 Profile* profile, | 224 Profile* profile, |
| 212 const base::Callback<void(bool)>& return_result) { | 225 const base::Callback<void(bool)>& return_result) { |
| 213 if (HasBeenShutdown(profile) || | 226 if (HasBeenShutdown(profile) || |
| 214 HasBookmarks(profile) || | 227 HasBookmarks(profile) || |
| 215 HasSyncedExtensions(profile)) { | 228 HasSyncedExtensions(profile)) { |
| 216 return_result.Run(true); | 229 return_result.Run(true); |
| 217 return; | 230 return; |
| 218 } | 231 } |
| 219 // Fire asynchronous queries for profile data. | 232 // Fire asynchronous queries for profile data. |
| 220 scoped_refptr<ProfileSigninConfirmationHelper> helper = | 233 scoped_refptr<ProfileSigninConfirmationHelper> helper = |
| 221 new ProfileSigninConfirmationHelper(profile, return_result); | 234 new ProfileSigninConfirmationHelper(profile, return_result); |
| 222 const int requests = 2; | 235 const int requests = 2; |
| 223 helper->set_pending_requests(requests); | 236 helper->set_pending_requests(requests); |
| 224 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); | 237 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); |
| 225 helper->CheckHasTypedURLs(); | 238 helper->CheckHasTypedURLs(); |
| 226 } | 239 } |
| 227 | 240 |
| 228 } // namespace ui | 241 } // namespace ui |
| OLD | NEW |