Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / importer / importer_list.h
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/callback_forward.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16
17 namespace importer {
18 struct SourceProfile;
19 }
20
21 // ImporterList detects installed browsers and profiles via
22 // DetectSourceProfilesWorker(). ImporterList lives on the UI thread.
23 class ImporterList {
24  public:
25   ImporterList();
26   ~ImporterList();
27
28   // Detects the installed browsers and their associated profiles, then stores
29   // their information in a list to be accessed via count() and
30   // GetSourceProfileAt(). The detection runs asynchronously.
31   //
32   // |locale|: As in DetectSourceProfilesWorker().
33   // |include_interactive_profiles|: True to include source profiles that
34   // require user interaction to read.
35   // |profiles_loaded_callback|: Assuming this ImporterList instance is still
36   // alive, run the callback when the source profile detection finishes.
37   void DetectSourceProfiles(const std::string& locale,
38                             bool include_interactive_profiles,
39                             const base::Closure& profiles_loaded_callback);
40
41   // Returns the number of different source profiles you can import from.
42   size_t count() const { return source_profiles_.size(); }
43
44   // Returns the SourceProfile at |index|. The profiles are ordered such that
45   // the profile at index 0 is the likely default browser. The SourceProfile
46   // should be passed to ImporterHost::StartImportSettings().
47   const importer::SourceProfile& GetSourceProfileAt(size_t index) const;
48
49  private:
50   // Called when the source profiles are loaded. Takes ownership of the
51   // loaded profiles in |profiles| and calls |profiles_loaded_callback|.
52   void SourceProfilesLoaded(
53       const base::Closure& profiles_loaded_callback,
54       const std::vector<importer::SourceProfile*>& profiles);
55
56   // The list of profiles with the default one first.
57   ScopedVector<importer::SourceProfile> source_profiles_;
58
59   base::WeakPtrFactory<ImporterList> weak_ptr_factory_;
60
61   DISALLOW_COPY_AND_ASSIGN(ImporterList);
62 };
63
64 #endif  // CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_