| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/web_resource/promo_resource_service.h" | 5 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/extensions/apps_promo.h" | 15 #include "chrome/browser/extensions/apps_promo.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sync/sync_ui_util.h" | 18 #include "chrome/browser/sync/sync_ui_util.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_version_info.h" | 21 #include "chrome/common/chrome_version_info.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "content/browser/browser_thread.h" | 23 #include "content/browser/browser_thread.h" |
| 24 #include "content/common/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Delay on first fetch so we don't interfere with startup. | 29 // Delay on first fetch so we don't interfere with startup. |
| 30 static const int kStartResourceFetchDelay = 5000; | 30 static const int kStartResourceFetchDelay = 5000; |
| 31 | 31 |
| 32 // Delay between calls to update the cache (48 hours), and 3 min in debug mode. | 32 // Delay between calls to update the cache (48 hours), and 3 min in debug mode. |
| 33 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; | 33 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; |
| 34 static const int kTestCacheUpdateDelay = 3 * 60 * 1000; | 34 static const int kTestCacheUpdateDelay = 3 * 60 * 1000; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 | 362 |
| 363 // If logo start or end times have changed, trigger a new web resource | 363 // If logo start or end times have changed, trigger a new web resource |
| 364 // notification, so that the logo on the NTP is updated. This check is | 364 // notification, so that the logo on the NTP is updated. This check is |
| 365 // outside the reading of the web resource data, because the absence of | 365 // outside the reading of the web resource data, because the absence of |
| 366 // dates counts as a triggering change if there were dates before. | 366 // dates counts as a triggering change if there were dates before. |
| 367 if (!(old_logo_start == logo_start) || | 367 if (!(old_logo_start == logo_start) || |
| 368 !(old_logo_end == logo_end)) { | 368 !(old_logo_end == logo_end)) { |
| 369 prefs_->SetDouble(prefs::kNTPCustomLogoStart, logo_start); | 369 prefs_->SetDouble(prefs::kNTPCustomLogoStart, logo_start); |
| 370 prefs_->SetDouble(prefs::kNTPCustomLogoEnd, logo_end); | 370 prefs_->SetDouble(prefs::kNTPCustomLogoEnd, logo_end); |
| 371 NotificationService* service = NotificationService::current(); | 371 content::NotificationService* service = |
| 372 content::NotificationService::current(); |
| 372 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 373 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 373 content::Source<WebResourceService>(this), | 374 content::Source<WebResourceService>(this), |
| 374 NotificationService::NoDetails()); | 375 content::NotificationService::NoDetails()); |
| 375 } | 376 } |
| 376 } | 377 } |
| 377 | 378 |
| 378 void PromoResourceService::UnpackSyncPromoSignal( | 379 void PromoResourceService::UnpackSyncPromoSignal( |
| 379 const DictionaryValue& parsed_json) { | 380 const DictionaryValue& parsed_json) { |
| 380 #if defined(OS_CHROMEOS) | 381 #if defined(OS_CHROMEOS) |
| 381 // Don't bother with this signal on ChromeOS. Users are already synced. | 382 // Don't bother with this signal on ChromeOS. Users are already synced. |
| 382 return; | 383 return; |
| 383 #endif | 384 #endif |
| 384 | 385 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 412 !base::StringToInt(question.substr(build_index + 1), &new_group_max)) { | 413 !base::StringToInt(question.substr(build_index + 1), &new_group_max)) { |
| 413 // If anything about the response was invalid or this build is no longer | 414 // If anything about the response was invalid or this build is no longer |
| 414 // targeted and there are existing prefs, clear them and notify. | 415 // targeted and there are existing prefs, clear them and notify. |
| 415 if (prefs_->HasPrefPath(prefs::kNTPSyncPromoGroup) || | 416 if (prefs_->HasPrefPath(prefs::kNTPSyncPromoGroup) || |
| 416 prefs_->HasPrefPath(prefs::kNTPSyncPromoGroupMax)) { | 417 prefs_->HasPrefPath(prefs::kNTPSyncPromoGroupMax)) { |
| 417 // Make sure we clear first, as the following notification may possibly | 418 // Make sure we clear first, as the following notification may possibly |
| 418 // depend on calling CanShowSyncPromo synchronously. | 419 // depend on calling CanShowSyncPromo synchronously. |
| 419 prefs_->ClearPref(prefs::kNTPSyncPromoGroup); | 420 prefs_->ClearPref(prefs::kNTPSyncPromoGroup); |
| 420 prefs_->ClearPref(prefs::kNTPSyncPromoGroupMax); | 421 prefs_->ClearPref(prefs::kNTPSyncPromoGroupMax); |
| 421 // Notify the NTP resource cache if the promo has been disabled. | 422 // Notify the NTP resource cache if the promo has been disabled. |
| 422 NotificationService::current()->Notify( | 423 content::NotificationService::current()->Notify( |
| 423 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 424 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 424 content::Source<WebResourceService>(this), | 425 content::Source<WebResourceService>(this), |
| 425 NotificationService::NoDetails()); | 426 content::NotificationService::NoDetails()); |
| 426 } | 427 } |
| 427 return; | 428 return; |
| 428 } | 429 } |
| 429 | 430 |
| 430 // TODO(dbeam): Add automagic hour group bumper to parsing? | 431 // TODO(dbeam): Add automagic hour group bumper to parsing? |
| 431 | 432 |
| 432 // If we successfully parsed a response and it differs from our user prefs, | 433 // If we successfully parsed a response and it differs from our user prefs, |
| 433 // set pref for next time to compare. | 434 // set pref for next time to compare. |
| 434 if (new_group_max != prefs_->GetInteger(prefs::kNTPSyncPromoGroupMax)) | 435 if (new_group_max != prefs_->GetInteger(prefs::kNTPSyncPromoGroupMax)) |
| 435 prefs_->SetInteger(prefs::kNTPSyncPromoGroupMax, new_group_max); | 436 prefs_->SetInteger(prefs::kNTPSyncPromoGroupMax, new_group_max); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 447 if (!prefs->HasPrefPath(prefs::kNTPSyncPromoGroup)) { | 448 if (!prefs->HasPrefPath(prefs::kNTPSyncPromoGroup)) { |
| 448 prefs->SetInteger(prefs::kNTPSyncPromoGroup, | 449 prefs->SetInteger(prefs::kNTPSyncPromoGroup, |
| 449 base::RandInt(1, kSyncPromoNumberOfGroups)); | 450 base::RandInt(1, kSyncPromoNumberOfGroups)); |
| 450 } | 451 } |
| 451 | 452 |
| 452 // A response is not kept if the build wasn't targeted, so the only thing | 453 // A response is not kept if the build wasn't targeted, so the only thing |
| 453 // required to check is the group this client has been tagged in. | 454 // required to check is the group this client has been tagged in. |
| 454 return prefs->GetInteger(prefs::kNTPSyncPromoGroupMax) >= | 455 return prefs->GetInteger(prefs::kNTPSyncPromoGroupMax) >= |
| 455 prefs->GetInteger(prefs::kNTPSyncPromoGroup); | 456 prefs->GetInteger(prefs::kNTPSyncPromoGroup); |
| 456 } | 457 } |
| OLD | NEW |