diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-06 20:19:29 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-06 20:19:29 +0000 |
commit | cd1c78349190f4084424fe9790f2548b0d52167a (patch) | |
tree | d2786ce9f424ddf04ebca6be6d3183bb3463c875 /chrome | |
parent | 0ef42ff9d9de850a881cfa66f96d4217695a2186 (diff) | |
download | chromium_src-cd1c78349190f4084424fe9790f2548b0d52167a.zip chromium_src-cd1c78349190f4084424fe9790f2548b0d52167a.tar.gz chromium_src-cd1c78349190f4084424fe9790f2548b0d52167a.tar.bz2 |
Add a ping delay time master preference.
BUG=1953127
Review URL: http://codereview.chromium.org/149135
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19978 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_main.cc | 5 | ||||
-rw-r--r-- | chrome/browser/rlz/rlz.cc | 17 | ||||
-rw-r--r-- | chrome/browser/rlz/rlz.h | 17 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 32 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.h | 19 |
5 files changed, 69 insertions, 21 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 0222697..349a226 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -51,6 +51,7 @@ #include "chrome/common/pref_service.h" #include "chrome/common/result_codes.h" #include "chrome/installer/util/google_update_settings.h" +#include "chrome/installer/util/master_preferences.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/net_resources.h" @@ -663,10 +664,12 @@ int BrowserMain(const MainFunctionParams& parameters) { win_util::ScopedCOMInitializer com_initializer; + int delay = 0; + installer_util::GetDistributionPingDelay(FilePath(), delay); // Init the RLZ library. This just binds the dll and schedules a task on the // file thread to be run sometime later. If this is the first run we record // the installation event. - RLZTracker::InitRlzDelayed(base::DIR_MODULE, is_first_run); + RLZTracker::InitRlzDelayed(base::DIR_MODULE, is_first_run, delay); #endif // Config the network module so it has access to resources. diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc index 96ea0c2..a280be2 100644 --- a/chrome/browser/rlz/rlz.cc +++ b/chrome/browser/rlz/rlz.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -287,13 +287,22 @@ bool RLZTracker::InitRlz(int directory_key) { return LoadRLZLibrary(directory_key); } -bool RLZTracker::InitRlzDelayed(int directory_key, bool first_run) { +bool RLZTracker::InitRlzDelayed(int directory_key, bool first_run, int delay) { + // Maximum and minimum delay we would allow to be set through master + // preferences. Somewhat arbitrary, may need to be adjusted in future. + const int kMaxDelay = 200 * 1000; + const int kMinDelay = 20 * 1000; + + delay *= 1000; + delay = (delay < kMinDelay) ? kMinDelay : delay; + delay = (delay > kMaxDelay) ? kMaxDelay : delay; + if (!OmniBoxUsageObserver::used()) new OmniBoxUsageObserver(); + // Schedule the delayed init items. - const int kNinetySeconds = 90 * 1000; MessageLoop::current()->PostDelayedTask(FROM_HERE, - new DelayedInitTask(directory_key, first_run), kNinetySeconds); + new DelayedInitTask(directory_key, first_run), delay); return true; } diff --git a/chrome/browser/rlz/rlz.h b/chrome/browser/rlz/rlz.h index f9936ba..b4f1b9c4 100644 --- a/chrome/browser/rlz/rlz.h +++ b/chrome/browser/rlz/rlz.h @@ -1,9 +1,9 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_RLZ_RLZ_H__ -#define CHROME_BROWSER_RLZ_RLZ_H__ +#ifndef CHROME_BROWSER_RLZ_RLZ_H_ +#define CHROME_BROWSER_RLZ_RLZ_H_ #include <string> @@ -69,10 +69,11 @@ class RLZTracker { // This function is intended primarily for testing. static bool InitRlz(int directory_key); - // Like InitRlz() this function the RLZ library services for use in chrome. - // Besides binding the dll, it schedules a delayed task that performs the - // daily ping and registers the some events when 'first-run' is true. - static bool InitRlzDelayed(int directory_key, bool first_run); + // Like InitRlz() this function initializes the RLZ library services for use + // in chrome. Besides binding the dll, it schedules a delayed task (delayed + // by |delay| seconds) that performs the daily ping and registers some events + // when 'first-run' is true. + static bool InitRlzDelayed(int directory_key, bool first_run, int delay); // Records an RLZ event. Some events can be access point independent. // Returns false it the event could not be recorded. Requires write access @@ -96,4 +97,4 @@ class RLZTracker { DISALLOW_IMPLICIT_CONSTRUCTORS(RLZTracker); }; -#endif // CHROME_BROWSER_RLZ_RLZ_H__ +#endif // CHROME_BROWSER_RLZ_RLZ_H_ diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index c59bc1d..4ff8b2f 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -1,12 +1,13 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/installer/util/master_preferences.h" #include "base/file_util.h" #include "base/logging.h" +#include "base/path_service.h" #include "chrome/common/json_value_serializer.h" -#include "chrome/installer/util/master_preferences.h" namespace { @@ -50,6 +51,8 @@ const wchar_t kDistroImportSearchPref[] = L"import_search_engine"; const wchar_t kDistroImportHistoryPref[] = L"import_history"; // Boolean pref that triggers silent import of the default browser bookmarks. const wchar_t kDistroImportBookmarksPref[] = L"import_bookmarks"; +// RLZ ping delay in seconds +const wchar_t kDistroPingDelay[] = L"ping_delay"; // Register Chrome as default browser for the current user. const wchar_t kMakeChromeDefaultForUser[] = L"make_chrome_default_for_user"; // The following boolean prefs have the same semantics as the corresponding @@ -74,6 +77,31 @@ const wchar_t kAltFirstRunBubble[] = L"oem_bubble"; // Boolean pref that triggers silent import of the default browser homepage. const wchar_t kDistroImportHomePagePref[] = L"import_home_page"; +bool GetDistributionPingDelay(const FilePath& master_prefs_path, + int& delay) { + FilePath master_prefs = master_prefs_path; + if (master_prefs.empty()) { + if (!PathService::Get(base::DIR_EXE, &master_prefs)) + return false; + master_prefs = master_prefs.Append(installer_util::kDefaultMasterPrefs); + } + + if (!file_util::PathExists(master_prefs)) + return false; + + scoped_ptr<DictionaryValue> json_root( + GetPrefsFromFile(master_prefs.ToWStringHack())); + if (!json_root.get()) + return false; + + DictionaryValue* distro = NULL; + if (!json_root->GetDictionary(L"distribution", &distro) || + !distro->GetInteger(kDistroPingDelay, &delay)) + return false; + + return true; +} + int ParseDistributionPreferences(const std::wstring& master_prefs_path) { if (!file_util::PathExists(master_prefs_path)) return MASTER_PROFILE_NOT_FOUND; diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h index c83464e..856d53e 100644 --- a/chrome/installer/util/master_preferences.h +++ b/chrome/installer/util/master_preferences.h @@ -1,16 +1,18 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // This file contains functions processing master preference file used by // setup and first run. -#ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__ -#define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__ +#ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ +#define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ #include <string> #include <vector> +#include "base/file_util.h" + namespace installer_util { // This is the default name for the master preferences file used to pre-set @@ -60,6 +62,11 @@ enum MasterPrefResult { MASTER_PROFILE_IMPORT_HOME_PAGE = 0x1 << 16 }; +// This function gets ping delay (ping_delay in the sample above) from master +// preferences. +bool GetDistributionPingDelay(const FilePath& master_prefs_path, + int& delay); + // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function parses the distribution // section of the preferences file. @@ -81,7 +88,8 @@ enum MasterPrefResult { // "system_level": false, // "verbose_logging": true, // "require_eula": true, -// "alternate_shortcut_text": false +// "alternate_shortcut_text": false, +// "ping_delay": 40 // }, // "browser": { // "show_home_button": true @@ -119,7 +127,6 @@ int ParseDistributionPreferences(const std::wstring& master_prefs_path); // preferences file does not contain such list the vector is empty. std::vector<std::wstring> ParseFirstRunTabs( const std::wstring& master_prefs_path); - } -#endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__ +#endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ |