1// Copyright (c) 2011 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_PROFILE_IMPORT_PROCESS_HOST_H_
6#define CHROME_BROWSER_IMPORTER_PROFILE_IMPORT_PROCESS_HOST_H_
7#pragma once
8
9#include <string>
10#include <vector>
11
12#include "base/basictypes.h"
13#include "base/compiler_specific.h"
14#include "base/memory/ref_counted.h"
15#include "chrome/browser/importer/importer_data_types.h"
16#include "chrome/browser/importer/profile_writer.h"
17#include "content/browser/browser_child_process_host.h"
18#include "content/browser/browser_thread.h"
19
20class ProfileImportProcessClient;
21
22namespace webkit_glue {
23struct PasswordForm;
24}
25
26// Browser-side host to a profile import process.  This class lives only on
27// the IO thread.  It passes messages back to the |thread_id_| thread through
28// a client object.
29class ProfileImportProcessHost : public BrowserChildProcessHost {
30 public:
31  // |import_process_client| implements callbacks which are triggered by
32  // incoming IPC messages.  This client creates an interface between IPC
33  // messages received by the ProfileImportProcessHost and the internal
34  // importer_bridge.
35  // |thread_id| gives the thread where the client lives. The
36  // ProfileImportProcessHost spawns tasks on this thread for the client.
37  ProfileImportProcessHost(ProfileImportProcessClient* import_process_client,
38                           BrowserThread::ID thread_id);
39  virtual ~ProfileImportProcessHost();
40
41  // |source_profile|, |items|, and |import_to_bookmark_bar| are all needed by
42  // the external importer process.
43  bool StartProfileImportProcess(const importer::SourceProfile& source_profile,
44                                 uint16 items,
45                                 bool import_to_bookmark_bar);
46
47  // Cancel the external import process.
48  bool CancelProfileImportProcess();
49
50  // Report that an item has been successfully imported.  We need to make
51  // sure that all import messages have come across the wire before the
52  // external import process shuts itself down.
53  bool ReportImportItemFinished(importer::ImportItem item);
54
55 protected:
56  // This method is virtual to be overridden by tests.
57  virtual FilePath GetProfileImportProcessCmd();
58
59 private:
60  // Launch the new process.
61  bool StartProcess();
62
63  // Called by the external importer process to send messages back to the
64  // ImportProcessClient.
65  virtual bool OnMessageReceived(const IPC::Message& message);
66
67  // BrowserChildProcessHost:
68  virtual void OnProcessCrashed(int exit_code) OVERRIDE;
69  virtual bool CanShutdown() OVERRIDE;
70
71  // Receives messages to be passed back to the importer host.
72  scoped_refptr<ProfileImportProcessClient> import_process_client_;
73
74  // The thread where the import_process_client_ lives.
75  BrowserThread::ID thread_id_;
76
77  DISALLOW_COPY_AND_ASSIGN(ProfileImportProcessHost);
78};
79
80#endif  // CHROME_BROWSER_IMPORTER_PROFILE_IMPORT_PROCESS_HOST_H_
81