Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / importer / importer_list.h
blob74c45d35e0977aa4273c72ad731fd06c12544f12
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_
8 #include <string>
9 #include <vector>
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"
17 namespace importer {
18 class ImporterListObserver;
19 struct SourceProfile;
22 class ImporterList : public base::RefCountedThreadSafe<ImporterList> {
23 public:
24 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
37 // after destruction.
38 void set_observer(importer::ImporterListObserver* observer) {
39 observer_ = 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_; }
63 private:
64 friend class base::RefCountedThreadSafe<ImporterList>;
66 ~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
71 // available).
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
86 // returned.
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.
97 bool is_observed_;
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_