OLD | NEW |
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 #ifndef CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ | 5 #ifndef CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ |
6 #define CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ | 6 #define CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/string16.h" |
13 #include "base/time.h" | 14 #include "base/time.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "chrome/browser/history/history_types.h" | 16 #include "chrome/browser/history/history_types.h" |
16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 | 18 |
18 class BookmarkModel; | 19 class BookmarkModel; |
19 class Profile; | 20 class Profile; |
20 class TemplateURL; | 21 class TemplateURL; |
21 | 22 |
22 namespace webkit_glue { | 23 namespace webkit_glue { |
23 struct PasswordForm; | 24 struct PasswordForm; |
24 } | 25 } |
25 | 26 |
26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
27 struct IE7PasswordInfo; | 28 struct IE7PasswordInfo; |
28 #endif | 29 #endif |
29 | 30 |
30 // ProfileWriter encapsulates profile for writing entries into it. | 31 // ProfileWriter encapsulates profile for writing entries into it. |
31 // This object must be invoked on UI thread. | 32 // This object must be invoked on UI thread. |
32 class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> { | 33 class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> { |
33 public: | 34 public: |
34 // Used to identify how the bookmarks are added. | |
35 enum BookmarkOptions { | |
36 // Indicates the bookmark should only be added if unique. Uniqueness is done | |
37 // by title, url and path. That is, if this is passed to AddBookmarks, the | |
38 // bookmark is added only if there is no other URL with the same url, path | |
39 // and title. | |
40 ADD_IF_UNIQUE = 1 << 0, | |
41 | |
42 // Indicates the bookmarks should be added to the bookmark bar. | |
43 IMPORT_TO_BOOKMARK_BAR = 1 << 1, | |
44 | |
45 // Indicates the bookmark bar is not shown. | |
46 BOOKMARK_BAR_DISABLED = 1 << 2 | |
47 }; | |
48 | |
49 struct BookmarkEntry { | 35 struct BookmarkEntry { |
50 BookmarkEntry(); | 36 BookmarkEntry(); |
51 ~BookmarkEntry(); | 37 ~BookmarkEntry(); |
52 | 38 |
53 bool in_toolbar; | 39 bool in_toolbar; |
54 bool is_folder; | 40 bool is_folder; |
55 GURL url; | 41 GURL url; |
56 std::vector<string16> path; | 42 std::vector<string16> path; |
57 string16 title; | 43 string16 title; |
58 base::Time creation_time; | 44 base::Time creation_time; |
(...skipping 12 matching lines...) Expand all Loading... |
71 | 57 |
72 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
73 virtual void AddIE7PasswordInfo(const IE7PasswordInfo& info); | 59 virtual void AddIE7PasswordInfo(const IE7PasswordInfo& info); |
74 #endif | 60 #endif |
75 | 61 |
76 virtual void AddHistoryPage(const std::vector<history::URLRow>& page, | 62 virtual void AddHistoryPage(const std::vector<history::URLRow>& page, |
77 history::VisitSource visit_source); | 63 history::VisitSource visit_source); |
78 | 64 |
79 virtual void AddHomepage(const GURL& homepage); | 65 virtual void AddHomepage(const GURL& homepage); |
80 | 66 |
81 // Adds the bookmarks to the BookmarkModel. | 67 // Adds the |bookmarks| to the bookmark model. |
82 // |options| is a bitmask of BookmarkOptions and dictates how and | 68 // |
83 // which bookmarks are added. If the bitmask contains IMPORT_TO_BOOKMARK_BAR, | 69 // (a) If the bookmarks bar is empty: |
84 // then any entries with a value of true for in_toolbar are added to | 70 // (i) If |bookmarks| includes at least one bookmark that was originally |
85 // the bookmark bar. If the bitmask does not contain IMPORT_TO_BOOKMARK_BAR | 71 // located in a toolbar, all such bookmarks are imported directly to |
86 // then the folder name the bookmarks are added to is uniqued based on | 72 // the toolbar; any other bookmarks are imported to a subfolder in |
87 // |first_folder_name|. For example, if |first_folder_name| is 'foo' | 73 // the toolbar. |
88 // and a folder with the name 'foo' already exists in the other | 74 // (i) If |bookmarks| includes no bookmarks that were originally located |
89 // bookmarks folder, then the folder name 'foo 2' is used. | 75 // in a toolbar, all bookmarks are imported directly to the toolbar. |
90 // If |options| contains ADD_IF_UNIQUE, then the bookmark is added only | 76 // (b) If the bookmarks bar is not empty, all bookmarks are imported to a |
91 // if another bookmarks does not exist with the same title, path and | 77 // subfolder in the toolbar. |
92 // url. | 78 // |
93 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmark, | 79 // In either case, if a subfolder is created, the name will be the value of |
94 const string16& first_folder_name, | 80 // |top_level_folder_name|, unless a folder with this name already exists. |
95 int options); | 81 // If a folder with this name already exists, then the name is uniquified. |
| 82 // For example, if |first_folder_name| is 'Imported from IE' and a folder with |
| 83 // the name 'Imported from IE' already exists in the bookmarks toolbar, then |
| 84 // we will instead create a subfolder named 'Imported from IE (1)'. |
| 85 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, |
| 86 const string16& top_level_folder_name); |
96 | 87 |
97 virtual void AddFavicons( | 88 virtual void AddFavicons( |
98 const std::vector<history::ImportedFaviconUsage>& favicons); | 89 const std::vector<history::ImportedFaviconUsage>& favicons); |
99 | 90 |
100 // Add the TemplateURLs in |template_urls| to the local store and make the | 91 // Add the TemplateURLs in |template_urls| to the local store and make the |
101 // TemplateURL at |default_keyword_index| the default keyword (does not set | 92 // TemplateURL at |default_keyword_index| the default keyword (does not set |
102 // a default keyword if it is -1). The local store becomes the owner of the | 93 // a default keyword if it is -1). The local store becomes the owner of the |
103 // TemplateURLs. Some TemplateURLs in |template_urls| may conflict (same | 94 // TemplateURLs. Some TemplateURLs in |template_urls| may conflict (same |
104 // keyword or same host name in the URL) with existing TemplateURLs in the | 95 // keyword or same host name in the URL) with existing TemplateURLs in the |
105 // local store, in which case the existing ones takes precedence and the | 96 // local store, in which case the existing ones takes precedence and the |
106 // duplicate in |template_urls| are deleted. | 97 // duplicate in |template_urls| are deleted. |
107 // If unique_on_host_and_path a TemplateURL is only added if there is not an | 98 // If unique_on_host_and_path a TemplateURL is only added if there is not an |
108 // existing TemplateURL that has a replaceable search url with the same | 99 // existing TemplateURL that has a replaceable search url with the same |
109 // host+path combination. | 100 // host+path combination. |
110 | |
111 virtual void AddKeywords(const std::vector<TemplateURL*>& template_urls, | 101 virtual void AddKeywords(const std::vector<TemplateURL*>& template_urls, |
112 int default_keyword_index, | 102 int default_keyword_index, |
113 bool unique_on_host_and_path); | 103 bool unique_on_host_and_path); |
114 | 104 |
115 // Shows the bookmarks toolbar. | |
116 void ShowBookmarkBar(); | |
117 | |
118 protected: | 105 protected: |
119 friend class base::RefCountedThreadSafe<ProfileWriter>; | 106 friend class base::RefCountedThreadSafe<ProfileWriter>; |
120 | 107 |
121 virtual ~ProfileWriter(); | 108 virtual ~ProfileWriter(); |
122 | 109 |
123 private: | 110 private: |
124 // Generates a unique folder name. If folder_name is not unique, then this | |
125 // repeatedly tests for '|folder_name| + (i)' until a unique name is found. | |
126 string16 GenerateUniqueFolderName(BookmarkModel* model, | |
127 const string16& folder_name); | |
128 | |
129 // Returns true if a bookmark exists with the same url, title and path | |
130 // as |entry|. |first_folder_name| is the name to use for the first | |
131 // path entry if |import_to_bookmark_bar| is true. | |
132 bool DoesBookmarkExist(BookmarkModel* model, | |
133 const BookmarkEntry& entry, | |
134 const string16& first_folder_name, | |
135 bool import_to_bookmark_bar); | |
136 | |
137 Profile* const profile_; | 111 Profile* const profile_; |
138 | 112 |
139 DISALLOW_COPY_AND_ASSIGN(ProfileWriter); | 113 DISALLOW_COPY_AND_ASSIGN(ProfileWriter); |
140 }; | 114 }; |
141 | 115 |
142 #endif // CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ | 116 #endif // CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ |
OLD | NEW |