first_run.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_ 6#define CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/compiler_specific.h" 13#include "base/gtest_prod_util.h" 14#include "base/memory/ref_counted.h" 15#include "content/public/browser/notification_observer.h" 16#include "content/public/browser/notification_registrar.h" 17#include "ui/gfx/native_widget_types.h" 18 19class CommandLine; 20class GURL; 21class Profile; 22 23namespace base { 24class FilePath; 25} 26 27namespace user_prefs { 28class PrefRegistrySyncable; 29} 30 31// This namespace contains the chrome first-run installation actions needed to 32// fully test the custom installer. It also contains the opposite actions to 33// execute during uninstall. When the first run UI is ready we won't 34// do the actions unconditionally. Currently the only action is to create a 35// desktop shortcut. 36// 37// The way we detect first-run is by looking at a 'sentinel' file. 38// If it does not exist we understand that we need to do the first time 39// install work for this user. After that the sentinel file is created. 40namespace first_run { 41 42enum AutoImportState { 43 AUTO_IMPORT_NONE = 0, 44 AUTO_IMPORT_CALLED = 1 << 0, 45 AUTO_IMPORT_PROFILE_IMPORTED = 1 << 1, 46 AUTO_IMPORT_BOOKMARKS_FILE_IMPORTED = 1 << 2, 47}; 48 49enum FirstRunBubbleMetric { 50 FIRST_RUN_BUBBLE_SHOWN = 0, // The search engine bubble was shown. 51 FIRST_RUN_BUBBLE_CHANGE_INVOKED, // The bubble's "Change" was invoked. 52 NUM_FIRST_RUN_BUBBLE_METRICS 53}; 54 55// Options for the first run bubble. The default is FIRST_RUN_BUBBLE_DONT_SHOW. 56// FIRST_RUN_BUBBLE_SUPPRESS is stronger in that FIRST_RUN_BUBBLE_SHOW should 57// never be set once FIRST_RUN_BUBBLE_SUPPRESS is set. 58enum FirstRunBubbleOptions { 59 FIRST_RUN_BUBBLE_DONT_SHOW, 60 FIRST_RUN_BUBBLE_SUPPRESS, 61 FIRST_RUN_BUBBLE_SHOW, 62}; 63 64enum ProcessMasterPreferencesResult { 65 DO_FIRST_RUN_TASKS = 0, // Should do the first run tasks. 66 SKIP_FIRST_RUN_TASKS, // Should skip the first run tasks. 67 EULA_EXIT_NOW, // Should immediately exit due to EULA flow. 68}; 69 70// See ProcessMasterPreferences for more info about this structure. 71struct MasterPrefs { 72 MasterPrefs(); 73 ~MasterPrefs(); 74 75 // TODO(macourteau): as part of the master preferences refactoring effort, 76 // remove items from here which are being stored temporarily only to be later 77 // dumped into local_state. Also see related TODO in chrome_browser_main.cc. 78 79 int ping_delay; 80 bool homepage_defined; 81 int do_import_items; 82 int dont_import_items; 83 bool make_chrome_default; 84 bool suppress_first_run_default_browser_prompt; 85 std::vector<GURL> new_tabs; 86 std::vector<GURL> bookmarks; 87 std::string import_bookmarks_path; 88 std::string variations_seed; 89 std::string suppress_default_browser_prompt_for_version; 90}; 91 92// Returns true if this is the first time chrome is run for this user. 93bool IsChromeFirstRun(); 94 95// Creates the sentinel file that signals that chrome has been configured. 96bool CreateSentinel(); 97 98// Get RLZ ping delay pref name. 99std::string GetPingDelayPrefName(); 100 101// Register user preferences used by the MasterPrefs structure. 102void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); 103 104// Removes the sentinel file created in ConfigDone(). Returns false if the 105// sentinel file could not be removed. 106bool RemoveSentinel(); 107 108// Sets the kShowFirstRunBubbleOption local state pref so that the browser 109// shows the bubble once the main message loop gets going (or refrains from 110// showing the bubble, if |show_bubble| is not FIRST_RUN_BUBBLE_SHOW). 111// Once FIRST_RUN_BUBBLE_SUPPRESS is set, no other value can be set. 112// Returns false if the pref service could not be retrieved. 113bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option); 114 115// Sets a flag that will cause ShouldShowWelcomePage to return true 116// exactly once, so that the browser loads the welcome tab once the 117// message loop gets going. 118void SetShouldShowWelcomePage(); 119 120// Returns true if the welcome page should be shown. 121// 122// This will return true only once: The first time it is called after 123// SetShouldShowWelcomePage() is called. 124bool ShouldShowWelcomePage(); 125 126// Sets a flag that will cause ShouldDoPersonalDataManagerFirstRun() 127// to return true exactly once, so that the browser loads 128// PersonalDataManager once the main message loop gets going. 129void SetShouldDoPersonalDataManagerFirstRun(); 130 131// Returns true if the autofill personal data manager first-run action 132// should be taken. 133// 134// This will return true only once, the first time it is called after 135// SetShouldDoPersonalDataManagerFirstRun() is called. 136bool ShouldDoPersonalDataManagerFirstRun(); 137 138// Log a metric for the "FirstRun.SearchEngineBubble" histogram. 139void LogFirstRunMetric(FirstRunBubbleMetric metric); 140 141// Automatically import history and home page (and search engine, if 142// ShouldShowSearchEngineDialog is true). Also imports bookmarks from file if 143// |import_bookmarks_path| is not empty. 144void AutoImport(Profile* profile, 145 bool homepage_defined, 146 int import_items, 147 int dont_import_items, 148 const std::string& import_bookmarks_path); 149 150// Does remaining first run tasks for |profile| and makes Chrome default browser 151// if |make_chrome_default|. This can pop the first run consent dialog on linux. 152void DoPostImportTasks(Profile* profile, bool make_chrome_default); 153 154// Returns the current state of AutoImport as recorded in a bitfield formed from 155// values in AutoImportState. 156uint16 auto_import_state(); 157 158// Set a master preferences file path that overrides platform defaults. 159void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs); 160 161// The master preferences is a JSON file with the same entries as the 162// 'Default\Preferences' file. This function locates this file from a standard 163// location and processes it so it becomes the default preferences in the 164// profile pointed to by |user_data_dir|. After processing the file, the 165// function returns a value from the ProcessMasterPreferencesResult enum, 166// indicating whether the first run flow should be shown, skipped, or whether 167// the browser should exit. 168// 169// This function destroys any existing prefs file and it is meant to be 170// invoked only on first run. 171// 172// See chrome/installer/util/master_preferences.h for a description of 173// 'master_preferences' file. 174ProcessMasterPreferencesResult ProcessMasterPreferences( 175 const base::FilePath& user_data_dir, 176 MasterPrefs* out_prefs); 177 178// Show the first run search engine bubble at the first appropriate opportunity. 179// This bubble may be delayed by other UI, like global errors and sync promos. 180class FirstRunBubbleLauncher : public content::NotificationObserver { 181 public: 182 // Show the bubble at the first appropriate opportunity. This function 183 // instantiates a FirstRunBubbleLauncher, which manages its own lifetime. 184 static void ShowFirstRunBubbleSoon(); 185 186 private: 187 FirstRunBubbleLauncher(); 188 virtual ~FirstRunBubbleLauncher(); 189 190 // content::NotificationObserver override: 191 virtual void Observe(int type, 192 const content::NotificationSource& source, 193 const content::NotificationDetails& details) OVERRIDE; 194 195 content::NotificationRegistrar registrar_; 196 197 DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleLauncher); 198}; 199 200} // namespace first_run 201 202#endif // CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_ 203