OLD | NEW |
| (Empty) |
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 #include "chrome/browser/importer/importer_type.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/metrics/histogram.h" | |
9 #include "chrome/browser/importer/bookmarks_file_importer.h" | |
10 #include "chrome/browser/importer/firefox3_importer.h" | |
11 | |
12 #if defined(OS_WIN) | |
13 #include "chrome/browser/importer/ie_importer.h" | |
14 #endif | |
15 | |
16 #if defined(OS_MACOSX) | |
17 #include <CoreFoundation/CoreFoundation.h> | |
18 #include "base/mac/foundation_util.h" | |
19 #include "chrome/browser/importer/safari_importer.h" | |
20 #endif | |
21 | |
22 namespace importer { | |
23 | |
24 namespace { | |
25 | |
26 // The enum used to register importer use. | |
27 enum ImporterTypeMetrics { | |
28 IMPORTER_METRICS_UNKNOWN = 0, | |
29 #if defined(OS_WIN) | |
30 IMPORTER_METRICS_IE = 1, | |
31 #endif | |
32 IMPORTER_METRICS_FIREFOX2 = 2, // obsolete | |
33 IMPORTER_METRICS_FIREFOX3 = 3, | |
34 #if defined(OS_MACOSX) | |
35 IMPORTER_METRICS_SAFARI = 4, | |
36 #endif | |
37 IMPORTER_METRICS_GOOGLE_TOOLBAR5 = 5, // obsolete | |
38 IMPORTER_METRICS_BOOKMARKS_FILE = 6, | |
39 | |
40 // Insert new values here. Never remove any existing values, as this enum is | |
41 // used to bucket a UMA histogram, and removing values breaks that. | |
42 IMPORTER_METRICS_SIZE | |
43 }; | |
44 | |
45 | |
46 } // namespace | |
47 | |
48 Importer* CreateImporterByType(ImporterType type) { | |
49 switch (type) { | |
50 #if defined(OS_WIN) | |
51 case TYPE_IE: | |
52 return new IEImporter(); | |
53 #endif | |
54 case TYPE_BOOKMARKS_FILE: | |
55 return new BookmarksFileImporter(); | |
56 case TYPE_FIREFOX3: | |
57 return new Firefox3Importer(); | |
58 #if defined(OS_MACOSX) | |
59 case TYPE_SAFARI: | |
60 return new SafariImporter(base::mac::GetUserLibraryPath()); | |
61 #endif | |
62 default: | |
63 NOTREACHED(); | |
64 return NULL; | |
65 } | |
66 NOTREACHED(); | |
67 return NULL; | |
68 } | |
69 | |
70 void LogImporterUseToMetrics(const std::string& metric_postfix, | |
71 ImporterType type) { | |
72 ImporterTypeMetrics metrics_type = IMPORTER_METRICS_UNKNOWN; | |
73 switch (type) { | |
74 case TYPE_UNKNOWN: | |
75 metrics_type = IMPORTER_METRICS_UNKNOWN; | |
76 break; | |
77 #if defined(OS_WIN) | |
78 case TYPE_IE: | |
79 metrics_type = IMPORTER_METRICS_IE; | |
80 break; | |
81 #endif | |
82 case TYPE_FIREFOX3: | |
83 metrics_type = IMPORTER_METRICS_FIREFOX3; | |
84 break; | |
85 #if defined(OS_MACOSX) | |
86 case TYPE_SAFARI: | |
87 metrics_type = IMPORTER_METRICS_SAFARI; | |
88 break; | |
89 #endif | |
90 case TYPE_BOOKMARKS_FILE: | |
91 metrics_type = IMPORTER_METRICS_BOOKMARKS_FILE; | |
92 break; | |
93 } | |
94 | |
95 // Note: This leaks memory, which is the expected behavior as the factory | |
96 // creates and owns the histogram. | |
97 base::HistogramBase* histogram = | |
98 base::LinearHistogram::FactoryGet( | |
99 "Import.ImporterType." + metric_postfix, | |
100 1, | |
101 IMPORTER_METRICS_SIZE, | |
102 IMPORTER_METRICS_SIZE + 1, | |
103 base::HistogramBase::kUmaTargetedHistogramFlag); | |
104 histogram->Add(metrics_type); | |
105 } | |
106 | |
107 } // namespace importer | |
OLD | NEW |