1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
// 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/browser/first_run.h"
#import "base/scoped_nsobject.h"
#include "base/sys_string_conversions.h"
#import "chrome/app/breakpad_mac.h"
#import "chrome/browser/cocoa/first_run_dialog.h"
#import "chrome/browser/cocoa/import_progress_dialog.h"
#include "chrome/browser/importer/importer.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/google_update_settings.h"
//------------------ Start Temporary Code ---------------------
// The Mac version used to store first run in the user defaults, this has
// now been moved to the profile directory like other platforms.
// These functions are here to use for migration, they should be removed
// in the near future once most people are upgraded.
// This should be removed after 2 dev release cycles following the checkin
// of this code, or by 15-Sept-2009. Whichever comes first.
namespace old_first_run_mac {
const NSString *kOldUsageStatsPrefName = @"usagestats";
// returns true if the first run sentinel is present in the dictionary
// false if no sentinel is present.
// |usage_stats_enabled| - Where the usage stats previously enabled?
bool IsOldChromeFirstRunFromDictionary(NSDictionary *dict,
bool *usage_stats_enabled) {
*usage_stats_enabled = false;
// Use presence of kOldUsageStatsPrefName key as an indicator of whether or
// not this is the first run.
NSNumber* val = [dict objectForKey:kOldUsageStatsPrefName];
if (val == nil) {
return false;
}
if ([val respondsToSelector:@selector(boolValue)]) {
*usage_stats_enabled = [val boolValue] ? true : false;
}
return true;
}
bool IsOldChromeFirstRun(bool *usage_stats_enabled) {
NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
NSDictionary* defaults_dict = [std_defaults dictionaryRepresentation];
return IsOldChromeFirstRunFromDictionary(defaults_dict, usage_stats_enabled);
}
// Remove the old first run key from the defaults dictionary.
void RemoveOldFirstRunDefaultsKey() {
NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
[std_defaults removeObjectForKey:kOldUsageStatsPrefName];
[std_defaults synchronize];
}
// returns:
// true - If old first run sentinel found and migration was performed.
// false - no previous first run sentinel found.
bool MigrateOldFirstRun() {
bool usage_stats_enabled = false;
if (!IsOldChromeFirstRun(&usage_stats_enabled))
return false;
FirstRun::CreateSentinel();
GoogleUpdateSettings::SetCollectStatsConsent(usage_stats_enabled);
// Migrate old first run data.
#if defined(GOOGLE_CHROME_BUILD)
// Breakpad is normally enabled very early in the startup process,
// however, on the first run it's off by default. If the user opts-in to
// stats, enable breakpad.
if (usage_stats_enabled) {
InitCrashReporter();
InitCrashProcessInfo();
}
#endif // GOOGLE_CHROME_BUILD
RemoveOldFirstRunDefaultsKey();
return true;
}
} // namespace old_first_run_mac
//------------------ End Temporary Code ---------------------
// Class that handles conducting the first run operation.
// FirstRunController deletes itself when the first run operation ends.
class FirstRunController : public ImportObserver {
public:
explicit FirstRunController();
virtual ~FirstRunController() {}
// Overridden methods from ImportObserver.
virtual void ImportCanceled() {
FirstRunDone();
}
virtual void ImportComplete() {
FirstRunDone();
}
// Display first run UI, start the import and return when it's all over.
bool DoFirstRun(Profile* profile, ProcessSingleton* process_singleton);
private:
// This method closes the first run window and quits the message loop so that
// the Chrome startup can continue. This should be called when all the
// first run tasks are done.
void FirstRunDone();
scoped_refptr<ImporterHost> importer_host_;
DISALLOW_COPY_AND_ASSIGN(FirstRunController);
};
bool OpenFirstRunDialog(Profile* profile,
bool homepage_defined,
ProcessSingleton* process_singleton) {
FirstRunController* controller = new FirstRunController;
return controller->DoFirstRun(profile, process_singleton);
}
FirstRunController::FirstRunController()
: importer_host_(new ImporterHost) {
}
void FirstRunController::FirstRunDone() {
// Set preference to show first run bubble and welcome page.
// TODO(jeremy): Implement
// FirstRun::SetShowFirstRunBubblePref();
// FirstRun::SetShowWelcomePagePref();
delete this;
}
bool FirstRunController::DoFirstRun(Profile* profile,
ProcessSingleton* process_singleton) {
// This object is responsible for deleting itself, make sure that happens.
scoped_ptr<FirstRunController> gc(this);
// Breakpad should not be enabled on first run until the user has explicitly
// opted-into stats.
// TODO: The behavior we probably want here is to enable Breakpad on first run
// but display a confirmation dialog before sending a crash report so we
// respect a user's privacy while still getting any crashes that might happen
// before this point. Then remove the need for that dialog here.
DCHECK(!IsCrashReporterEnabled());
//------------------ Start Temporary Code ---------------------
// Migrate old first run format.
if (old_first_run_mac::MigrateOldFirstRun()) {
return true;
}
//------------------ End Temporary Code ---------------------
scoped_nsobject<FirstRunDialogController> dialog(
[[FirstRunDialogController alloc] init]);
// Set list of browsers we know how to import.
ssize_t profiles_count = importer_host_->GetAvailableProfileCount();
// TODO(jeremy): Test on newly created account.
// TODO(jeremy): Correctly handle case where no browsers to import from
// are detected.
NSMutableArray *browsers = [NSMutableArray arrayWithCapacity:profiles_count];
for (int i = 0; i < profiles_count; ++i) {
std::wstring profile = importer_host_->GetSourceProfileNameAt(i);
[browsers addObject:base::SysWideToNSString(profile)];
}
[dialog.get() setBrowserImportList:browsers];
// FirstRunDialogController will call exit if "Cancel" is clicked.
[dialog.get() showWindow:nil];
// If user clicked cancel, bail - browser_main will return if we haven't
// turned off the first run flag when this function returns.
if ([dialog.get() userDidCancel]) {
return false;
}
// Don't enable stats in Chromium.
bool stats_enabled = false;
#if defined(GOOGLE_CHROME_BUILD)
stats_enabled = [dialog.get() statsEnabled] ? true : false;
#endif // GOOGLE_CHROME_BUILD
FirstRun::CreateSentinel();
GoogleUpdateSettings::SetCollectStatsConsent(stats_enabled);
#if defined(GOOGLE_CHROME_BUILD)
// Breakpad is normally enabled very early in the startup process,
// however, on the first run it's off by default. If the user opts-in to
// stats, enable breakpad.
if (stats_enabled) {
InitCrashReporter();
InitCrashProcessInfo();
}
#endif // GOOGLE_CHROME_BUILD
// If selected set as default browser.
BOOL make_default_browser = [dialog.get() makeDefaultBrowser];
if (make_default_browser) {
bool success = ShellIntegration::SetAsDefaultBrowser();
DCHECK(success);
}
// Import bookmarks.
if ([dialog.get() importBookmarks]) {
const ProfileInfo& source_profile = importer_host_->GetSourceProfileInfoAt(
[dialog.get() browserImportSelectedIndex]);
int16 items = source_profile.services_supported;
// TODO(port): Do the actual import in a new process like Windows.
gc.release();
StartImportingWithUI(nil, items, importer_host_.get(),
source_profile, profile, this, true);
}
return true;
}
|