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