summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer/importer_list.h
blob: b7a245232bda3234d5ff276bfe03064663217289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_
#define CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_

#include <stddef.h>

#include <string>
#include <vector>

#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "chrome/common/importer/importer_data_types.h"

// ImporterList detects installed browsers and profiles via
// DetectSourceProfilesWorker(). ImporterList lives on the UI thread.
class ImporterList {
 public:
  ImporterList();
  ~ImporterList();

  // Detects the installed browsers and their associated profiles, then stores
  // their information in a list to be accessed via count() and
  // GetSourceProfileAt(). The detection runs asynchronously.
  //
  // |locale|: As in DetectSourceProfilesWorker().
  // |include_interactive_profiles|: True to include source profiles that
  // require user interaction to read.
  // |profiles_loaded_callback|: Assuming this ImporterList instance is still
  // alive, run the callback when the source profile detection finishes.
  void DetectSourceProfiles(const std::string& locale,
                            bool include_interactive_profiles,
                            const base::Closure& profiles_loaded_callback);

  // Returns the number of different source profiles you can import from.
  size_t count() const { return source_profiles_.size(); }

  // Returns the SourceProfile at |index|. The profiles are ordered such that
  // the profile at index 0 is the likely default browser. The SourceProfile
  // should be passed to ImporterHost::StartImportSettings().
  const importer::SourceProfile& GetSourceProfileAt(size_t index) const;

 private:
  // Called when the source profiles are loaded. Copies the loaded profiles
  // in |profiles| and calls |profiles_loaded_callback|.
  void SourceProfilesLoaded(
      const base::Closure& profiles_loaded_callback,
      const std::vector<importer::SourceProfile>& profiles);

  // The list of profiles with the default one first.
  std::vector<importer::SourceProfile> source_profiles_;

  base::WeakPtrFactory<ImporterList> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(ImporterList);
};

#endif  // CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_