Home | History | Annotate | Download | only in first_run
      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 
     13 class CommandLine;
     14 class GURL;
     15 class Profile;
     16 
     17 namespace base {
     18 class FilePath;
     19 }
     20 
     21 namespace user_prefs {
     22 class PrefRegistrySyncable;
     23 }
     24 
     25 // This namespace contains the chrome first-run installation actions needed to
     26 // fully test the custom installer. It also contains the opposite actions to
     27 // execute during uninstall. When the first run UI is ready we won't
     28 // do the actions unconditionally. Currently the only action is to create a
     29 // desktop shortcut.
     30 //
     31 // The way we detect first-run is by looking at a 'sentinel' file.
     32 // If it does not exist we understand that we need to do the first time
     33 // install work for this user. After that the sentinel file is created.
     34 namespace first_run {
     35 
     36 enum AutoImportState {
     37   AUTO_IMPORT_NONE = 0,
     38   AUTO_IMPORT_CALLED = 1 << 0,
     39   AUTO_IMPORT_PROFILE_IMPORTED = 1 << 1,
     40   AUTO_IMPORT_BOOKMARKS_FILE_IMPORTED = 1 << 2,
     41 };
     42 
     43 enum FirstRunBubbleMetric {
     44   FIRST_RUN_BUBBLE_SHOWN = 0,       // The search engine bubble was shown.
     45   FIRST_RUN_BUBBLE_CHANGE_INVOKED,  // The bubble's "Change" was invoked.
     46   NUM_FIRST_RUN_BUBBLE_METRICS
     47 };
     48 
     49 // Options for the first run bubble. The default is FIRST_RUN_BUBBLE_DONT_SHOW.
     50 // FIRST_RUN_BUBBLE_SUPPRESS is stronger in that FIRST_RUN_BUBBLE_SHOW should
     51 // never be set once FIRST_RUN_BUBBLE_SUPPRESS is set.
     52 enum FirstRunBubbleOptions {
     53   FIRST_RUN_BUBBLE_DONT_SHOW,
     54   FIRST_RUN_BUBBLE_SUPPRESS,
     55   FIRST_RUN_BUBBLE_SHOW,
     56 };
     57 
     58 enum ProcessMasterPreferencesResult {
     59   FIRST_RUN_PROCEED = 0,  // Proceed with first run.
     60   EULA_EXIT_NOW,          // Should immediately exit due to EULA flow.
     61 };
     62 
     63 // See ProcessMasterPreferences for more info about this structure.
     64 struct MasterPrefs {
     65   MasterPrefs();
     66   ~MasterPrefs();
     67 
     68   // TODO(macourteau): as part of the master preferences refactoring effort,
     69   // remove items from here which are being stored temporarily only to be later
     70   // dumped into local_state. Also see related TODO in chrome_browser_main.cc.
     71 
     72   int ping_delay;
     73   bool homepage_defined;
     74   int do_import_items;
     75   int dont_import_items;
     76   bool make_chrome_default_for_user;
     77   bool suppress_first_run_default_browser_prompt;
     78   std::vector<GURL> new_tabs;
     79   std::vector<GURL> bookmarks;
     80   std::string import_bookmarks_path;
     81   std::string variations_seed;
     82   std::string suppress_default_browser_prompt_for_version;
     83 };
     84 
     85 // Returns true if this is the first time chrome is run for this user.
     86 bool IsChromeFirstRun();
     87 
     88 // Returns true if |command_line|'s switches explicitly specify that first run
     89 // should be suppressed in the current run.
     90 bool IsFirstRunSuppressed(const CommandLine& command_line);
     91 
     92 // Creates the first run sentinel if needed. This should only be called after
     93 // the process singleton has been grabbed by the current process
     94 // (http://crbug.com/264694).
     95 void CreateSentinelIfNeeded();
     96 
     97 // Get RLZ ping delay pref name.
     98 std::string GetPingDelayPrefName();
     99 
    100 // Register user preferences used by the MasterPrefs structure.
    101 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
    102 
    103 // Removes the sentinel file created in ConfigDone(). Returns false if the
    104 // sentinel file could not be removed.
    105 bool RemoveSentinel();
    106 
    107 // Sets the kShowFirstRunBubbleOption local state pref so that the browser
    108 // shows the bubble once the main message loop gets going (or refrains from
    109 // showing the bubble, if |show_bubble| is not FIRST_RUN_BUBBLE_SHOW).
    110 // Once FIRST_RUN_BUBBLE_SUPPRESS is set, no other value can be set.
    111 // Returns false if the pref service could not be retrieved.
    112 bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option);
    113 
    114 // Sets a flag that will cause ShouldShowWelcomePage to return true
    115 // exactly once, so that the browser loads the welcome tab once the
    116 // message loop gets going.
    117 void SetShouldShowWelcomePage();
    118 
    119 // Returns true if the welcome page should be shown.
    120 //
    121 // This will return true only once: The first time it is called after
    122 // SetShouldShowWelcomePage() is called.
    123 bool ShouldShowWelcomePage();
    124 
    125 // Sets a flag that will cause ShouldDoPersonalDataManagerFirstRun()
    126 // to return true exactly once, so that the browser loads
    127 // PersonalDataManager once the main message loop gets going.
    128 void SetShouldDoPersonalDataManagerFirstRun();
    129 
    130 // Returns true if the autofill personal data manager first-run action
    131 // should be taken.
    132 //
    133 // This will return true only once, the first time it is called after
    134 // SetShouldDoPersonalDataManagerFirstRun() is called.
    135 bool ShouldDoPersonalDataManagerFirstRun();
    136 
    137 // Log a metric for the "FirstRun.SearchEngineBubble" histogram.
    138 void LogFirstRunMetric(FirstRunBubbleMetric metric);
    139 
    140 // Automatically import history and home page (and search engine, if
    141 // ShouldShowSearchEngineDialog is true). Also imports bookmarks from file if
    142 // |import_bookmarks_path| is not empty.
    143 void AutoImport(Profile* profile,
    144                 bool homepage_defined,
    145                 int import_items,
    146                 int dont_import_items,
    147                 const std::string& import_bookmarks_path);
    148 
    149 // Does remaining first run tasks. This can pop the first run consent dialog on
    150 // linux. |make_chrome_default_for_user| is the value of
    151 // kMakeChromeDefaultForUser in master_preferences which contributes to the
    152 // decision of making chrome default browser in post import tasks.
    153 void DoPostImportTasks(Profile* profile, bool make_chrome_default_for_user);
    154 
    155 // Returns the current state of AutoImport as recorded in a bitfield formed from
    156 // values in AutoImportState.
    157 uint16 auto_import_state();
    158 
    159 // Set a master preferences file path that overrides platform defaults.
    160 void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs);
    161 
    162 // The master preferences is a JSON file with the same entries as the
    163 // 'Default\Preferences' file. This function locates this file from a standard
    164 // location and processes it so it becomes the default preferences in the
    165 // profile pointed to by |user_data_dir|. After processing the file, the
    166 // function returns a value from the ProcessMasterPreferencesResult enum,
    167 // indicating whether the first run flow should be shown, skipped, or whether
    168 // the browser should exit.
    169 //
    170 // This function destroys any existing prefs file and it is meant to be
    171 // invoked only on first run.
    172 //
    173 // See chrome/installer/util/master_preferences.h for a description of
    174 // 'master_preferences' file.
    175 ProcessMasterPreferencesResult ProcessMasterPreferences(
    176     const base::FilePath& user_data_dir,
    177     MasterPrefs* out_prefs);
    178 
    179 }  // namespace first_run
    180 
    181 #endif  // CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_
    182