Home | History | Annotate | Download | only in importer
      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.
      4 
      5 #ifndef CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_
      6 #define CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_
      7 
      8 #include <vector>
      9 
     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 "chrome/browser/history/history_types.h"
     17 #include "url/gurl.h"
     18 
     19 struct ImportedBookmarkEntry;
     20 struct ImportedFaviconUsage;
     21 class Profile;
     22 class TemplateURL;
     23 
     24 namespace content {
     25 struct PasswordForm;
     26 }
     27 
     28 #if defined(OS_WIN)
     29 struct IE7PasswordInfo;
     30 #endif
     31 
     32 // ProfileWriter encapsulates profile for writing entries into it.
     33 // This object must be invoked on UI thread.
     34 class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> {
     35  public:
     36   explicit ProfileWriter(Profile* profile);
     37 
     38   // These functions return true if the corresponding model has been loaded.
     39   // If the models haven't been loaded, the importer waits to run until they've
     40   // completed.
     41   virtual bool BookmarkModelIsLoaded() const;
     42   virtual bool TemplateURLServiceIsLoaded() const;
     43 
     44   // Helper methods for adding data to local stores.
     45   virtual void AddPasswordForm(const content::PasswordForm& form);
     46 
     47 #if defined(OS_WIN)
     48   virtual void AddIE7PasswordInfo(const IE7PasswordInfo& info);
     49 #endif
     50 
     51   virtual void AddHistoryPage(const history::URLRows& page,
     52                               history::VisitSource visit_source);
     53 
     54   virtual void AddHomepage(const GURL& homepage);
     55 
     56   // Adds the |bookmarks| to the bookmark model.
     57   //
     58   // (a) If the bookmarks bar is empty:
     59   //     (i) If |bookmarks| includes at least one bookmark that was originally
     60   //         located in a toolbar, all such bookmarks are imported directly to
     61   //         the toolbar; any other bookmarks are imported to a subfolder in
     62   //         the toolbar.
     63   //     (i) If |bookmarks| includes no bookmarks that were originally located
     64   //         in a toolbar, all bookmarks are imported directly to the toolbar.
     65   // (b) If the bookmarks bar is not empty, all bookmarks are imported to a
     66   //     subfolder in the toolbar.
     67   //
     68   // In either case, if a subfolder is created, the name will be the value of
     69   // |top_level_folder_name|, unless a folder with this name already exists.
     70   // If a folder with this name already exists, then the name is uniquified.
     71   // For example, if |first_folder_name| is 'Imported from IE' and a folder with
     72   // the name 'Imported from IE' already exists in the bookmarks toolbar, then
     73   // we will instead create a subfolder named 'Imported from IE (1)'.
     74   virtual void AddBookmarks(
     75       const std::vector<ImportedBookmarkEntry>& bookmarks,
     76       const string16& top_level_folder_name);
     77 
     78   virtual void AddFavicons(
     79       const std::vector<ImportedFaviconUsage>& favicons);
     80 
     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);
     91 
     92  protected:
     93   friend class base::RefCountedThreadSafe<ProfileWriter>;
     94 
     95   virtual ~ProfileWriter();
     96 
     97  private:
     98   Profile* const profile_;
     99 
    100   DISALLOW_COPY_AND_ASSIGN(ProfileWriter);
    101 };
    102 
    103 #endif  // CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_
    104