Home | History | Annotate | Download | only in first_run
      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
      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 #pragma once
      8 
      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 "ui/gfx/native_widget_types.h"
     16 
     17 class CommandLine;
     18 class FilePath;
     19 class GURL;
     20 class Profile;
     21 class ProcessSingleton;
     22 class ImporterHost;
     23 class ImporterList;
     24 
     25 // This class 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 class FirstRun {
     35  public:
     36   // There are three types of possible first run bubbles:
     37   enum BubbleType {
     38     LARGE_BUBBLE,      // The normal bubble, with search engine choice
     39     OEM_BUBBLE,        // Smaller bubble for OEM builds
     40     MINIMAL_BUBBLE     // Minimal bubble shown after search engine dialog
     41   };
     42 
     43   // See ProcessMasterPreferences for more info about this structure.
     44   struct MasterPrefs {
     45     MasterPrefs();
     46     ~MasterPrefs();
     47 
     48     int ping_delay;
     49     bool homepage_defined;
     50     int do_import_items;
     51     int dont_import_items;
     52     bool run_search_engine_experiment;
     53     bool randomize_search_engine_experiment;
     54     bool make_chrome_default;
     55     std::vector<GURL> new_tabs;
     56     std::vector<GURL> bookmarks;
     57   };
     58 
     59   // Import bookmarks and/or browser items (depending on platform support)
     60   // in this process. This function is paired with FirstRun::ImportSettings().
     61   // This function might or might not show a visible UI depending on the
     62   // cmdline parameters.
     63   static int ImportNow(Profile* profile, const CommandLine& cmdline);
     64 
     65   // Automatically import history and home page (and search engine, if
     66   // ShouldShowSearchEngineDialog is true).
     67   static void AutoImport(
     68       Profile* profile,
     69       bool homepage_defined,
     70       int import_items,
     71       int dont_import_items,
     72       bool search_engine_experiment,
     73       bool randomize_search_engine_experiment,
     74       bool make_chrome_default,
     75       ProcessSingleton* process_singleton);
     76 
     77   // Does platform specific setup. Called at the start of AutoImport.
     78   static void PlatformSetup();
     79 
     80   // Returns whether the first run should be "organic".
     81   static bool IsOrganicFirstRun();
     82 
     83   // The master preferences is a JSON file with the same entries as the
     84   // 'Default\Preferences' file. This function locates this file from a standard
     85   // location and processes it so it becomes the default preferences in the
     86   // profile pointed to by |user_data_dir|. After processing the file, the
     87   // function returns true if and only if showing the first run dialog is
     88   // needed. The detailed settings in the preference file are reported via
     89   // |preference_details|.
     90   //
     91   // This function destroys any existing prefs file and it is meant to be
     92   // invoked only on first run.
     93   //
     94   // See chrome/installer/util/master_preferences.h for a description of
     95   // 'master_preferences' file.
     96   static bool ProcessMasterPreferences(const FilePath& user_data_dir,
     97                                        MasterPrefs* out_prefs);
     98 
     99   // Returns true if this is the first time chrome is run for this user.
    100   static bool IsChromeFirstRun();
    101 
    102   // Creates the sentinel file that signals that chrome has been configured.
    103   static bool CreateSentinel();
    104 
    105   // Removes the sentinel file created in ConfigDone(). Returns false if the
    106   // sentinel file could not be removed.
    107   static bool RemoveSentinel();
    108 
    109   // Imports settings. This may be done in a separate process depending on the
    110   // platform, but it will always block until done. The return value indicates
    111   // success.
    112   static bool ImportSettings(Profile* profile,
    113                              scoped_refptr<ImporterHost> importer_host,
    114                              scoped_refptr<ImporterList> importer_list,
    115                              int items_to_import);
    116 
    117   // Sets the kShouldShowFirstRunBubble local state pref so that the browser
    118   // shows the bubble once the main message loop gets going (or refrains from
    119   // showing the bubble, if |show_bubble| is false). Returns false if the pref
    120   // could not be set. This function can be called multiple times, but only the
    121   // initial call will actually set the preference.
    122   static bool SetShowFirstRunBubblePref(bool show_bubble);
    123 
    124   // Sets the kShouldUseOEMFirstRunBubble local state pref so that the
    125   // browser shows the OEM first run bubble once the main message loop
    126   // gets going. Returns false if the pref could not be set.
    127   static bool SetOEMFirstRunBubblePref();
    128 
    129   // Sets the kShouldUseMinimalFirstRunBubble local state pref so that the
    130   // browser shows the minimal first run bubble once the main message loop
    131   // gets going. Returns false if the pref could not be set.
    132   static bool SetMinimalFirstRunBubblePref();
    133 
    134   // Sets the kShouldShowWelcomePage local state pref so that the browser
    135   // loads the welcome tab once the message loop gets going. Returns false
    136   // if the pref could not be set.
    137   static bool SetShowWelcomePagePref();
    138 
    139   // Sets the kAutofillPersonalDataManagerFirstRun local state pref so that the
    140   // browser loads PersonalDataManager once the main message loop gets going.
    141   // Returns false if the pref could not be set.
    142   static bool SetPersonalDataManagerFirstRunPref();
    143 
    144   // True if special circumstances should prevent the search engine ballot from
    145   // being shown.
    146   static bool SearchEngineSelectorDisallowed();
    147 
    148  private:
    149   friend class FirstRunTest;
    150   FRIEND_TEST_ALL_PREFIXES(Toolbar5ImporterTest, BookmarkParse);
    151 
    152 #if defined(OS_WIN)
    153   // Writes the EULA to a temporary file, returned in |*eula_path|, and returns
    154   // true if successful.
    155   static bool WriteEULAtoTempFile(FilePath* eula_path);
    156 
    157   // Launches the setup exe with the given parameter/value on the command-line,
    158   // waits for its termination, returns its exit code in |*ret_code|, and
    159   // returns true if the exit code is valid.
    160   static bool LaunchSetupWithParam(const std::string& param,
    161                                    const std::wstring& value,
    162                                    int* ret_code);
    163 
    164   // Installs a task to do an extensions update check once the extensions system
    165   // is running.
    166   static void DoDelayedInstallExtensions();
    167 
    168   // Imports settings in a separate process. It is the implementation of the
    169   // public version.  |skip_first_run_ui| is true if no first run UI should
    170   // appear (search engine dialog, Firefox import warning dialog).
    171   static bool ImportSettings(Profile* profile,
    172                              int importer_type,
    173                              int items_to_import,
    174                              const FilePath& import_path,
    175                              bool skip_first_run_ui,
    176                              gfx::NativeView parent_window);
    177 
    178   // Import browser items in this process. The browser and the items to
    179   // import are encoded int the command line.
    180   static int ImportFromBrowser(Profile* profile, const CommandLine& cmdline);
    181 
    182 #else
    183   static bool ImportBookmarks(const FilePath& import_bookmarks_path);
    184 #endif
    185 
    186   // Import bookmarks from an html file. The path to the file is provided in
    187   // the command line.
    188   static int ImportFromFile(Profile* profile, const CommandLine& cmdline);
    189 
    190   // Gives the full path to the sentinel file. The file might not exist.
    191   static bool GetFirstRunSentinelFilePath(FilePath* path);
    192 
    193   enum FirstRunState {
    194     FIRST_RUN_UNKNOWN,  // The state is not tested or set yet.
    195     FIRST_RUN_TRUE,
    196     FIRST_RUN_FALSE
    197   };
    198 
    199   // This variable should only be accessed through IsChromeFirstRun().
    200   static FirstRunState first_run_;
    201 
    202   // This class is for scoping purposes.
    203   DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun);
    204 };
    205 
    206 #endif  // CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_
    207