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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_
6 #define CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string16.h"
14 #include "base/time/time.h"
15 #include "build/build_config.h"
16 #include "components/favicon_base/favicon_usage_data.h"
17 #include "components/history/core/browser/history_types.h"
20 struct ImportedBookmarkEntry
;
30 struct IE7PasswordInfo
;
33 // ProfileWriter encapsulates profile for writing entries into it.
34 // This object must be invoked on UI thread.
35 class ProfileWriter
: public base::RefCountedThreadSafe
<ProfileWriter
> {
37 explicit ProfileWriter(Profile
* profile
);
39 // These functions return true if the corresponding model has been loaded.
40 // If the models haven't been loaded, the importer waits to run until they've
42 virtual bool BookmarkModelIsLoaded() const;
43 virtual bool TemplateURLServiceIsLoaded() const;
45 // Helper methods for adding data to local stores.
46 virtual void AddPasswordForm(const autofill::PasswordForm
& form
);
49 virtual void AddIE7PasswordInfo(const IE7PasswordInfo
& info
);
52 virtual void AddHistoryPage(const history::URLRows
& page
,
53 history::VisitSource visit_source
);
55 virtual void AddHomepage(const GURL
& homepage
);
57 // Adds the |bookmarks| to the bookmark model.
59 // (a) If the bookmarks bar is empty:
60 // (i) If |bookmarks| includes at least one bookmark that was originally
61 // located in a toolbar, all such bookmarks are imported directly to
62 // the toolbar; any other bookmarks are imported to a subfolder in
64 // (i) If |bookmarks| includes no bookmarks that were originally located
65 // in a toolbar, all bookmarks are imported directly to the toolbar.
66 // (b) If the bookmarks bar is not empty, all bookmarks are imported to a
67 // subfolder in the toolbar.
69 // In either case, if a subfolder is created, the name will be the value of
70 // |top_level_folder_name|, unless a folder with this name already exists.
71 // If a folder with this name already exists, then the name is uniquified.
72 // For example, if |first_folder_name| is 'Imported from IE' and a folder with
73 // the name 'Imported from IE' already exists in the bookmarks toolbar, then
74 // we will instead create a subfolder named 'Imported from IE (1)'.
75 virtual void AddBookmarks(
76 const std::vector
<ImportedBookmarkEntry
>& bookmarks
,
77 const base::string16
& top_level_folder_name
);
79 virtual void AddFavicons(const favicon_base::FaviconUsageDataList
& favicons
);
81 // Adds the TemplateURLs in |template_urls| to the local store. The local
82 // store becomes the owner of the TemplateURLs. Some TemplateURLs in
83 // |template_urls| may conflict (same keyword or same host name in the URL)
84 // with existing TemplateURLs in the local store, in which case the existing
85 // ones take precedence and the duplicates in |template_urls| are deleted.
86 // If |unique_on_host_and_path| is true, a TemplateURL is only added if there
87 // is not an existing TemplateURL that has a replaceable search url with the
88 // same host+path combination.
89 virtual void AddKeywords(ScopedVector
<TemplateURL
> template_urls
,
90 bool unique_on_host_and_path
);
92 // Adds the imported autofill entries to the autofill database.
93 virtual void AddAutofillFormDataEntries(
94 const std::vector
<autofill::AutofillEntry
>& autofill_entries
);
97 friend class base::RefCountedThreadSafe
<ProfileWriter
>;
99 virtual ~ProfileWriter();
102 Profile
* const profile_
;
104 DISALLOW_COPY_AND_ASSIGN(ProfileWriter
);
107 #endif // CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_