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_IMPORTER_LIST_H_ 6 #define CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "base/memory/ref_counted.h" 13 #include "base/memory/scoped_vector.h" 14 #include "base/strings/string16.h" 15 #include "content/public/browser/browser_thread.h" 16 17 namespace importer { 18 class ImporterListObserver; 19 struct SourceProfile; 20 } 21 22 class ImporterList : public base::RefCountedThreadSafe<ImporterList> { 23 public: 24 ImporterList(); 25 26 // Detects the installed browsers and their associated profiles, then stores 27 // their information in a list. It returns the list of description of all 28 // profiles. Calls into DetectSourceProfilesWorker() on the FILE thread to do 29 // the real work of detecting source profiles. |observer| must be non-NULL. 30 // |locale|: As in DetectSourceProfilesWorker(). 31 void DetectSourceProfiles(const std::string& locale, 32 importer::ImporterListObserver* observer); 33 34 // Sets the observer of this object. When the current observer is destroyed, 35 // this method should be called with a NULL |observer| so it is not notified 36 // after destruction. 37 void set_observer(importer::ImporterListObserver* observer) { 38 observer_ = observer; 39 } 40 41 // DEPRECATED: This method is synchronous and performs file operations which 42 // may end up blocking the current thread, which is usually the UI thread. 43 // |locale|: As in DetectSourceProfilesWorker(). 44 void DetectSourceProfilesHack(const std::string& locale); 45 46 // Returns the number of different source profiles you can import from. 47 size_t count() const { return source_profiles_.size(); } 48 49 // Returns the SourceProfile at |index|. The profiles are ordered such that 50 // the profile at index 0 is the likely default browser. The SourceProfile 51 // should be passed to ImporterHost::StartImportSettings(). 52 const importer::SourceProfile& GetSourceProfileAt(size_t index) const; 53 54 // Returns the SourceProfile for the given |importer_type|. 55 const importer::SourceProfile& GetSourceProfileForImporterType( 56 int importer_type) const; 57 58 // Tells interested callers if class is done loading source profiles. 59 bool source_profiles_loaded() const { return source_profiles_loaded_; } 60 61 private: 62 friend class base::RefCountedThreadSafe<ImporterList>; 63 64 ~ImporterList(); 65 66 // The worker method for DetectSourceProfiles(). Must be called on the FILE 67 // thread. |locale|:The application locale (it must be taken as an argument 68 // since this code runs on the FILE thread where GetApplicationLocale() isn't 69 // available). 70 void DetectSourceProfilesWorker(const std::string& locale); 71 72 // Called by DetectSourceProfilesWorker() on the source thread. This method 73 // notifies |observer_| that the source profiles are loaded. |profiles| is 74 // the vector of loaded profiles. 75 void SourceProfilesLoaded( 76 const std::vector<importer::SourceProfile*>& profiles); 77 78 // The list of profiles with the default one first. 79 ScopedVector<importer::SourceProfile> source_profiles_; 80 81 // The ID of the thread DetectSourceProfiles() is called on. Only valid after 82 // DetectSourceProfiles() is called and until SourceProfilesLoaded() has 83 // returned. 84 content::BrowserThread::ID source_thread_id_; 85 86 // Weak reference. Only valid after DetectSourceProfiles() is called and until 87 // SourceProfilesLoaded() has returned. 88 importer::ImporterListObserver* observer_; 89 90 // True if |observer_| is set during the lifetime of source profile detection. 91 // This hack is necessary in order to not use |observer_| != NULL as a method 92 // of determining whether this object is being observed or not. 93 // TODO(jhawkins): Remove once DetectSourceProfilesHack() is removed. 94 bool is_observed_; 95 96 // True if source profiles are loaded. 97 bool source_profiles_loaded_; 98 99 DISALLOW_COPY_AND_ASSIGN(ImporterList); 100 }; 101 102 #endif // CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_ 103