OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
12 #include "chrome/browser/bookmarks/bookmark_prompt_prefs.h" | 12 #include "chrome/browser/bookmarks/bookmark_prompt_prefs.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/defaults.h" | 14 #include "chrome/browser/defaults.h" |
15 #include "chrome/browser/history/history_service.h" | 15 #include "chrome/browser/history/history_service.h" |
16 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/common/chrome_version_info.h" | 23 #include "chrome/common/chrome_version_info.h" |
| 24 #include "chrome/common/metrics/variations/variation_ids.h" |
| 25 #include "chrome/common/metrics/variations/variations_util.h" |
24 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
25 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
27 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
28 | 30 |
29 using content::WebContents; | 31 using content::WebContents; |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
| 35 const char kBookmarkPromptTrialName[] = "BookmarkPrompt"; |
| 36 const char kBookmarkPromptDefaultGroup[] = "Disabled"; |
| 37 const char kBookmarkPromptControlGroup[] = "Control"; |
| 38 const char kBookmarkPromptExperimentGroup[] = "Experiment"; |
| 39 |
33 // This enum is used for the BookmarkPrompt.DisabledReason histogram. | 40 // This enum is used for the BookmarkPrompt.DisabledReason histogram. |
34 enum PromptDisabledReason { | 41 enum PromptDisabledReason { |
35 PROMPT_DISABLED_REASON_BY_IMPRESSION_COUNT, | 42 PROMPT_DISABLED_REASON_BY_IMPRESSION_COUNT, |
36 PROMPT_DISABLED_REASON_BY_MANUAL, | 43 PROMPT_DISABLED_REASON_BY_MANUAL, |
37 | 44 |
38 PROMPT_DISABLED_REASON_LIMIT, // Keep this last. | 45 PROMPT_DISABLED_REASON_LIMIT, // Keep this last. |
39 }; | 46 }; |
40 | 47 |
41 // This enum represents reason why we display bookmark prompt and for the | 48 // This enum represents reason why we display bookmark prompt and for the |
42 // BookmarkPrompt.DisplayReason histogram. | 49 // BookmarkPrompt.DisplayReason histogram. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 211 } |
205 | 212 |
206 // Enable bookmark prompt controller feature for 1% of new users for one month | 213 // Enable bookmark prompt controller feature for 1% of new users for one month |
207 // on canary. We'll change the date for stable channel once release date fixed. | 214 // on canary. We'll change the date for stable channel once release date fixed. |
208 // static | 215 // static |
209 bool BookmarkPromptController::IsEnabled() { | 216 bool BookmarkPromptController::IsEnabled() { |
210 // If manually create field trial available, we use it. | 217 // If manually create field trial available, we use it. |
211 const std::string manual_group_name = base::FieldTrialList::FindFullName( | 218 const std::string manual_group_name = base::FieldTrialList::FindFullName( |
212 "BookmarkPrompt"); | 219 "BookmarkPrompt"); |
213 if (!manual_group_name.empty()) | 220 if (!manual_group_name.empty()) |
214 return manual_group_name == "Experiment"; | 221 return manual_group_name == kBookmarkPromptExperimentGroup; |
215 | 222 |
216 const ExperimentDateRange* date_range = GetExperimentDateRange(); | 223 const ExperimentDateRange* date_range = GetExperimentDateRange(); |
217 if (!date_range) | 224 if (!date_range) |
218 return false; | 225 return false; |
219 | 226 |
220 scoped_refptr<base::FieldTrial> trial( | 227 scoped_refptr<base::FieldTrial> trial( |
221 base::FieldTrialList::FactoryGetFieldTrial( | 228 base::FieldTrialList::FactoryGetFieldTrial( |
222 "BookmarkPrompt", 100, "Disabled", | 229 kBookmarkPromptTrialName, 100, kBookmarkPromptDefaultGroup, |
223 date_range->expiration_date.year, | 230 date_range->expiration_date.year, |
224 date_range->expiration_date.month, | 231 date_range->expiration_date.month, |
225 date_range->expiration_date.day_of_month, NULL)); | 232 date_range->expiration_date.day_of_month, NULL)); |
226 trial->UseOneTimeRandomization(); | 233 trial->UseOneTimeRandomization(); |
227 trial->AppendGroup("Control", 99); | 234 trial->AppendGroup(kBookmarkPromptControlGroup, 99); |
228 trial->AppendGroup("Experiment", 1); | 235 trial->AppendGroup(kBookmarkPromptExperimentGroup, 1); |
| 236 |
| 237 chrome_variations::AssociateGoogleVariationID( |
| 238 chrome_variations::GOOGLE_UPDATE_SERVICE, |
| 239 kBookmarkPromptTrialName, kBookmarkPromptDefaultGroup, |
| 240 chrome_variations::BOOKMARK_PROMPT_TRIAL_DEFAULT); |
| 241 chrome_variations::AssociateGoogleVariationID( |
| 242 chrome_variations::GOOGLE_UPDATE_SERVICE, |
| 243 kBookmarkPromptTrialName, kBookmarkPromptControlGroup, |
| 244 chrome_variations::BOOKMARK_PROMPT_TRIAL_CONTROL); |
| 245 chrome_variations::AssociateGoogleVariationID( |
| 246 chrome_variations::GOOGLE_UPDATE_SERVICE, |
| 247 kBookmarkPromptTrialName, kBookmarkPromptExperimentGroup, |
| 248 chrome_variations::BOOKMARK_PROMPT_TRIAL_EXPERIMENT); |
229 | 249 |
230 const base::Time start_date = base::Time::FromLocalExploded( | 250 const base::Time start_date = base::Time::FromLocalExploded( |
231 date_range->install_date); | 251 date_range->install_date); |
232 const int64 install_time = | 252 const int64 install_time = |
233 g_browser_process->local_state()->GetInt64(prefs::kInstallDate); | 253 g_browser_process->local_state()->GetInt64(prefs::kInstallDate); |
234 // This must be called after the pref is initialized. | 254 // This must be called after the pref is initialized. |
235 DCHECK(install_time); | 255 DCHECK(install_time); |
236 const base::Time install_date = base::Time::FromTimeT(install_time); | 256 const base::Time install_date = base::Time::FromTimeT(install_time); |
237 | 257 |
238 if (install_date < start_date) { | 258 if (install_date < start_date) { |
239 trial->Disable(); | 259 trial->Disable(); |
240 return false; | 260 return false; |
241 } | 261 } |
242 return trial->group_name() == "Experiment"; | 262 return trial->group_name() == kBookmarkPromptExperimentGroup; |
243 } | 263 } |
244 | 264 |
245 void BookmarkPromptController::ActiveTabChanged(WebContents* old_contents, | 265 void BookmarkPromptController::ActiveTabChanged(WebContents* old_contents, |
246 WebContents* new_contents, | 266 WebContents* new_contents, |
247 int index, | 267 int index, |
248 bool user_gesture) { | 268 bool user_gesture) { |
249 SetWebContents(new_contents); | 269 SetWebContents(new_contents); |
250 } | 270 } |
251 | 271 |
252 void BookmarkPromptController::AddedBookmarkInternal(Browser* browser, | 272 void BookmarkPromptController::AddedBookmarkInternal(Browser* browser, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 registrar_.Remove( | 387 registrar_.Remove( |
368 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 388 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
369 content::Source<WebContents>(web_contents_)); | 389 content::Source<WebContents>(web_contents_)); |
370 } | 390 } |
371 web_contents_ = web_contents; | 391 web_contents_ = web_contents; |
372 if (web_contents_) { | 392 if (web_contents_) { |
373 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 393 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
374 content::Source<WebContents>(web_contents_)); | 394 content::Source<WebContents>(web_contents_)); |
375 } | 395 } |
376 } | 396 } |
OLD | NEW |