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 #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_H_ 6 #define CHROME_BROWSER_IMPORTER_IMPORTER_H_ 7 #pragma once 8 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "base/memory/ref_counted.h" 13 14 class ImporterBridge; 15 16 namespace importer { 17 struct SourceProfile; 18 } 19 20 // The base class of all importers. 21 class Importer : public base::RefCountedThreadSafe<Importer> { 22 public: 23 // All importers should implement this method by adding their import logic. 24 // And it will be run in file thread by ImporterHost. Since we do async 25 // import, the importer should invoke ImporterHost::NotifyImportEnded() to 26 // notify its host that import stuff have been finished. 27 virtual void StartImport(const importer::SourceProfile& source_profile, 28 uint16 items, 29 ImporterBridge* bridge) = 0; 30 31 // Cancels the import process. 32 virtual void Cancel(); 33 34 void set_import_to_bookmark_bar(bool import_to_bookmark_bar) { 35 import_to_bookmark_bar_ = import_to_bookmark_bar; 36 } 37 38 void set_bookmark_bar_disabled(bool bookmark_bar_disabled) { 39 bookmark_bar_disabled_ = bookmark_bar_disabled; 40 } 41 42 bool bookmark_bar_disabled() { return bookmark_bar_disabled_; } 43 bool cancelled() const { return cancelled_; } 44 45 protected: 46 friend class base::RefCountedThreadSafe<Importer>; 47 48 Importer(); 49 virtual ~Importer(); 50 51 // Given raw image data, decodes the icon, re-sampling to the correct size as 52 // necessary, and re-encodes as PNG data in the given output vector. Returns 53 // true on success. 54 static bool ReencodeFavicon(const unsigned char* src_data, 55 size_t src_len, 56 std::vector<unsigned char>* png_data); 57 58 bool import_to_bookmark_bar() const { return import_to_bookmark_bar_; } 59 60 scoped_refptr<ImporterBridge> bridge_; 61 62 private: 63 // True if the importer is created in the first run UI. 64 bool import_to_bookmark_bar_; 65 66 // Whether bookmark bar is disabled (not shown) for importer. This is set 67 // true during first run to prevent out of process bookmark importer from 68 // updating bookmark bar settings. 69 bool bookmark_bar_disabled_; 70 71 // True if the caller cancels the import process. 72 bool cancelled_; 73 74 DISALLOW_COPY_AND_ASSIGN(Importer); 75 }; 76 77 #endif // CHROME_BROWSER_IMPORTER_IMPORTER_H_ 78