Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/browser/themes/theme_service.cc

Issue 8919017: Split UserMetrics into API vs. implementation. Move API to content/public. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Version for commit (merged again). Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/string_split.h" 8 #include "base/string_split.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/themes/browser_theme_pack.h" 13 #include "chrome/browser/themes/browser_theme_pack.h"
14 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "content/browser/user_metrics.h"
18 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/user_metrics.h"
19 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
20 #include "grit/theme_resources_standard.h" 20 #include "grit/theme_resources_standard.h"
21 #include "grit/ui_resources.h" 21 #include "grit/ui_resources.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 23
24 #if defined(OS_WIN) && !defined(USE_AURA) 24 #if defined(OS_WIN) && !defined(USE_AURA)
25 #include "ui/views/widget/native_widget_win.h" 25 #include "ui/views/widget/native_widget_win.h"
26 #endif 26 #endif
27 27
28 using content::BrowserThread; 28 using content::BrowserThread;
29 using content::UserMetricsAction;
29 30
30 // Strings used in alignment properties. 31 // Strings used in alignment properties.
31 const char* ThemeService::kAlignmentTop = "top"; 32 const char* ThemeService::kAlignmentTop = "top";
32 const char* ThemeService::kAlignmentBottom = "bottom"; 33 const char* ThemeService::kAlignmentBottom = "bottom";
33 const char* ThemeService::kAlignmentLeft = "left"; 34 const char* ThemeService::kAlignmentLeft = "left";
34 const char* ThemeService::kAlignmentRight = "right"; 35 const char* ThemeService::kAlignmentRight = "right";
35 36
36 // Strings used in background tiling repetition properties. 37 // Strings used in background tiling repetition properties.
37 const char* ThemeService::kTilingNoRepeat = "no-repeat"; 38 const char* ThemeService::kTilingNoRepeat = "no-repeat";
38 const char* ThemeService::kTilingRepeatX = "repeat-x"; 39 const char* ThemeService::kTilingRepeatX = "repeat-x";
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Clear our image cache. 321 // Clear our image cache.
321 FreePlatformCaches(); 322 FreePlatformCaches();
322 323
323 DCHECK(extension); 324 DCHECK(extension);
324 DCHECK(extension->is_theme()); 325 DCHECK(extension->is_theme());
325 326
326 BuildFromExtension(extension); 327 BuildFromExtension(extension);
327 SaveThemeID(extension->id()); 328 SaveThemeID(extension->id());
328 329
329 NotifyThemeChanged(); 330 NotifyThemeChanged();
330 UserMetrics::RecordAction(UserMetricsAction("Themes_Installed")); 331 content::RecordAction(UserMetricsAction("Themes_Installed"));
331 } 332 }
332 333
333 void ThemeService::RemoveUnusedThemes() { 334 void ThemeService::RemoveUnusedThemes() {
334 if (!profile_) 335 if (!profile_)
335 return; 336 return;
336 ExtensionService* service = profile_->GetExtensionService(); 337 ExtensionService* service = profile_->GetExtensionService();
337 if (!service) 338 if (!service)
338 return; 339 return;
339 std::string current_theme = GetThemeID(); 340 std::string current_theme = GetThemeID();
340 std::vector<std::string> remove_list; 341 std::vector<std::string> remove_list;
341 const ExtensionSet* extensions = service->extensions(); 342 const ExtensionSet* extensions = service->extensions();
342 for (ExtensionSet::const_iterator it = extensions->begin(); 343 for (ExtensionSet::const_iterator it = extensions->begin();
343 it != extensions->end(); ++it) { 344 it != extensions->end(); ++it) {
344 if ((*it)->is_theme() && (*it)->id() != current_theme) { 345 if ((*it)->is_theme() && (*it)->id() != current_theme) {
345 remove_list.push_back((*it)->id()); 346 remove_list.push_back((*it)->id());
346 } 347 }
347 } 348 }
348 for (size_t i = 0; i < remove_list.size(); ++i) 349 for (size_t i = 0; i < remove_list.size(); ++i)
349 service->UninstallExtension(remove_list[i], false, NULL); 350 service->UninstallExtension(remove_list[i], false, NULL);
350 } 351 }
351 352
352 void ThemeService::UseDefaultTheme() { 353 void ThemeService::UseDefaultTheme() {
353 ClearAllThemeData(); 354 ClearAllThemeData();
354 NotifyThemeChanged(); 355 NotifyThemeChanged();
355 UserMetrics::RecordAction(UserMetricsAction("Themes_Reset")); 356 content::RecordAction(UserMetricsAction("Themes_Reset"));
356 } 357 }
357 358
358 void ThemeService::SetNativeTheme() { 359 void ThemeService::SetNativeTheme() {
359 UseDefaultTheme(); 360 UseDefaultTheme();
360 } 361 }
361 362
362 bool ThemeService::UsingDefaultTheme() const { 363 bool ThemeService::UsingDefaultTheme() const {
363 std::string id = GetThemeID(); 364 std::string id = GetThemeID();
364 return id == ThemeService::kDefaultThemeID || 365 return id == ThemeService::kDefaultThemeID ||
365 id == kDefaultThemeGalleryID; 366 id == kDefaultThemeGalleryID;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 bool loaded_pack = false; 579 bool loaded_pack = false;
579 580
580 // If we don't have a file pack, we're updating from an old version. 581 // If we don't have a file pack, we're updating from an old version.
581 FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); 582 FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename);
582 if (path != FilePath()) { 583 if (path != FilePath()) {
583 theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id); 584 theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id);
584 loaded_pack = theme_pack_.get() != NULL; 585 loaded_pack = theme_pack_.get() != NULL;
585 } 586 }
586 587
587 if (loaded_pack) { 588 if (loaded_pack) {
588 UserMetrics::RecordAction(UserMetricsAction("Themes.Loaded")); 589 content::RecordAction(UserMetricsAction("Themes.Loaded"));
589 } else { 590 } else {
590 // TODO(erg): We need to pop up a dialog informing the user that their 591 // TODO(erg): We need to pop up a dialog informing the user that their
591 // theme is being migrated. 592 // theme is being migrated.
592 ExtensionService* service = profile_->GetExtensionService(); 593 ExtensionService* service = profile_->GetExtensionService();
593 if (service) { 594 if (service) {
594 const Extension* extension = 595 const Extension* extension =
595 service->GetExtensionById(current_id, false); 596 service->GetExtensionById(current_id, false);
596 if (extension) { 597 if (extension) {
597 DLOG(ERROR) << "Migrating theme"; 598 DLOG(ERROR) << "Migrating theme";
598 BuildFromExtension(extension); 599 BuildFromExtension(extension);
599 UserMetrics::RecordAction(UserMetricsAction("Themes.Migrated")); 600 content::RecordAction(UserMetricsAction("Themes.Migrated"));
600 } else { 601 } else {
601 DLOG(ERROR) << "Theme is mysteriously gone."; 602 DLOG(ERROR) << "Theme is mysteriously gone.";
602 ClearAllThemeData(); 603 ClearAllThemeData();
603 UserMetrics::RecordAction(UserMetricsAction("Themes.Gone")); 604 content::RecordAction(UserMetricsAction("Themes.Gone"));
604 } 605 }
605 } 606 }
606 } 607 }
607 } 608 }
608 } 609 }
609 610
610 void ThemeService::NotifyThemeChanged() { 611 void ThemeService::NotifyThemeChanged() {
611 DVLOG(1) << "Sending BROWSER_THEME_CHANGED"; 612 DVLOG(1) << "Sending BROWSER_THEME_CHANGED";
612 // Redraw! 613 // Redraw!
613 content::NotificationService* service = 614 content::NotificationService* service =
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 void ThemeService::OnInfobarDisplayed() { 670 void ThemeService::OnInfobarDisplayed() {
670 number_of_infobars_++; 671 number_of_infobars_++;
671 } 672 }
672 673
673 void ThemeService::OnInfobarDestroyed() { 674 void ThemeService::OnInfobarDestroyed() {
674 number_of_infobars_--; 675 number_of_infobars_--;
675 676
676 if (number_of_infobars_ == 0) 677 if (number_of_infobars_ == 0)
677 RemoveUnusedThemes(); 678 RemoveUnusedThemes();
678 } 679 }
OLDNEW
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698