summaryrefslogtreecommitdiffstats
path: root/chrome/profile_import/profile_import_thread.h
blob: a81b816455fdcab7bba3230f8527c2f810ad21c3 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2011 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_PROFILE_IMPORT_PROFILE_IMPORT_THREAD_H_
#define CHROME_PROFILE_IMPORT_PROFILE_IMPORT_THREAD_H_
#pragma once

#include <vector>

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/importer/importer_data_types.h"
#include "chrome/browser/importer/profile_writer.h"
#include "content/common/child_thread.h"
#include "webkit/glue/password_form.h"

class DictionaryValue;
class ExternalProcessImporterBridge;
class GURL;
class Importer;
class TemplateURL;

namespace base {
class Thread;
}

namespace IPC {
class Message;
}

// This class represents the background thread which communicates with the
// importer work thread in the importer process.
class ProfileImportThread : public ChildThread {
 public:
  ProfileImportThread();
  virtual ~ProfileImportThread();

  // Returns the one profile import thread.
  static ProfileImportThread* current() {
    return static_cast<ProfileImportThread*>(ChildThread::current());
  }

  // Bridging methods, called from importer_bridge tasks posted here.
  void NotifyStarted();
  void NotifyItemStarted(importer::ImportItem item);
  void NotifyItemEnded(importer::ImportItem item);
  void NotifyEnded();

  // Bridging methods that move data back across the process boundary.
  void NotifyHistoryImportReady(const std::vector<history::URLRow>& rows,
                                history::VisitSource visit_source);
  void NotifyHomePageImportReady(const GURL& home_page);
  void NotifyBookmarksImportReady(
      const std::vector<ProfileWriter::BookmarkEntry>& bookmarks,
      const string16& first_folder_name,
      int options);
  void NotifyFaviconsImportReady(
      const std::vector<history::ImportedFaviconUsage>& favicons);
  void NotifyPasswordFormReady(const webkit_glue::PasswordForm& form);
  void NotifyKeywordsReady(const std::vector<TemplateURL*>& template_urls,
                           int default_keyword_index,
                           bool unique_on_host_and_path);

 private:
  // IPC messages
  virtual bool OnControlMessageReceived(const IPC::Message& msg);

  // Creates the importer and launches it in a new thread. Import is run on
  // a separate thread so that this thread can receive messages from the
  // main process (especially cancel requests) while the worker thread handles
  // the actual import.
  void OnImportStart(
      const importer::SourceProfile& source_profile,
      uint16 items,
      const DictionaryValue& localized_strings,
      bool import_to_bookmark_bar);

  // Calls cleanup to stop the import operation.
  void OnImportCancel();

  // Called from the main process to notify that an item has been received
  // from the import process.
  void OnImportItemFinished(uint16 item);

  // Release the process and ourselves.
  void Cleanup();

  // Thread that importer runs on, while ProfileImportThread handles messages
  // from the browser process.
  scoped_ptr<base::Thread> import_thread_;

  // Bridge object is passed to importer, so that it can send IPC calls
  // directly back to the ProfileImportProcessHost.
  scoped_refptr<ExternalProcessImporterBridge> bridge_;

  // A bitmask of importer::ImportItem.
  uint16 items_to_import_;

  // Importer of the appropriate type (Firefox, Safari, IE, etc.)
  scoped_refptr<Importer> importer_;

  DISALLOW_COPY_AND_ASSIGN(ProfileImportThread);
};

#endif  // CHROME_PROFILE_IMPORT_PROFILE_IMPORT_THREAD_H_