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_IMPORTER_LIST_H_
6 #define CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_
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"
18 class ImporterListObserver
;
22 class ImporterList
: public base::RefCountedThreadSafe
<ImporterList
> {
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
);
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
38 void set_observer(importer::ImporterListObserver
* observer
) {
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
);
48 // Returns the number of different source profiles you can import from.
49 size_t count() const { return source_profiles_
.size(); }
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;
56 // Returns the SourceProfile for the given |importer_type|.
57 const importer::SourceProfile
& GetSourceProfileForImporterType(
58 int importer_type
) const;
60 // Tells interested callers if class is done loading source profiles.
61 bool source_profiles_loaded() const { return source_profiles_loaded_
; }
64 friend class base::RefCountedThreadSafe
<ImporterList
>;
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
72 void DetectSourceProfilesWorker(const std::string
& locale
,
73 bool include_interactive_profiles
);
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
);
81 // The list of profiles with the default one first.
82 ScopedVector
<importer::SourceProfile
> source_profiles_
;
84 // The ID of the thread DetectSourceProfiles() is called on. Only valid after
85 // DetectSourceProfiles() is called and until SourceProfilesLoaded() has
87 content::BrowserThread::ID source_thread_id_
;
89 // Weak reference. Only valid after DetectSourceProfiles() is called and until
90 // SourceProfilesLoaded() has returned.
91 importer::ImporterListObserver
* observer_
;
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.
99 // True if source profiles are loaded.
100 bool source_profiles_loaded_
;
102 DISALLOW_COPY_AND_ASSIGN(ImporterList
);
105 #endif // CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_