profile_import_process_messages.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1// Copyright 2013 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// Multiply-included message file, no traditonal include guard.
6#include <string>
7#include <vector>
8
9#include "base/basictypes.h"
10#include "base/strings/string16.h"
11#include "base/values.h"
12#include "chrome/common/common_param_traits_macros.h"
13#include "chrome/common/importer/imported_bookmark_entry.h"
14#include "chrome/common/importer/imported_favicon_usage.h"
15#include "chrome/common/importer/importer_data_types.h"
16#include "chrome/common/importer/importer_url_row.h"
17#include "content/public/common/common_param_traits.h"
18#include "content/public/common/password_form.h"
19#include "ipc/ipc_message_macros.h"
20#include "ipc/ipc_message_utils.h"
21
22#ifndef CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_MESSAGES_H_
23#define CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_MESSAGES_H_
24
25namespace IPC {
26
27// Traits for importer::SourceProfile struct to pack/unpack.
28template <>
29struct ParamTraits<importer::SourceProfile> {
30  typedef importer::SourceProfile param_type;
31  static void Write(Message* m, const param_type& p) {
32    WriteParam(m, p.importer_name);
33    WriteParam(m, static_cast<int>(p.importer_type));
34    WriteParam(m, p.source_path);
35    WriteParam(m, p.app_path);
36    WriteParam(m, static_cast<int>(p.services_supported));
37    WriteParam(m, p.locale);
38  }
39  static bool Read(const Message* m, PickleIterator* iter, param_type* p) {
40    if (!ReadParam(m, iter, &p->importer_name))
41      return false;
42
43    int importer_type = 0;
44    if (!ReadParam(m, iter, &importer_type))
45      return false;
46    p->importer_type = static_cast<importer::ImporterType>(importer_type);
47
48    if (!ReadParam(m, iter, &p->source_path) ||
49        !ReadParam(m, iter, &p->app_path)) {
50        return false;
51    }
52
53    int services_supported = 0;
54    if (!ReadParam(m, iter, &services_supported))
55      return false;
56    p->services_supported = static_cast<uint16>(services_supported);
57
58    if (!ReadParam(m, iter, &p->locale))
59      return false;
60
61    return true;
62  }
63  static void Log(const param_type& p, std::string* l) {
64    l->append("(");
65    LogParam(p.importer_name, l);
66    l->append(", ");
67    LogParam(static_cast<int>(p.importer_type), l);
68    l->append(", ");
69    LogParam(p.source_path, l);
70    l->append(", ");
71    LogParam(p.app_path, l);
72    l->append(", ");
73    LogParam(static_cast<int>(p.services_supported), l);
74    l->append(", ");
75    LogParam(p.locale, l);
76    l->append(")");
77  }
78};  // ParamTraits<importer::SourceProfile>
79
80// Traits for ImporterURLRow to pack/unpack.
81template <>
82struct ParamTraits<ImporterURLRow> {
83  typedef ImporterURLRow param_type;
84  static void Write(Message* m, const param_type& p) {
85    WriteParam(m, p.url);
86    WriteParam(m, p.title);
87    WriteParam(m, p.visit_count);
88    WriteParam(m, p.typed_count);
89    WriteParam(m, p.last_visit);
90    WriteParam(m, p.hidden);
91  }
92  static bool Read(const Message* m, PickleIterator* iter, param_type* p) {
93    GURL url;
94    string16 title;
95    int visit_count, typed_count;
96    base::Time last_visit;
97    bool hidden;
98    if (!ReadParam(m, iter, &url) ||
99        !ReadParam(m, iter, &title) ||
100        !ReadParam(m, iter, &visit_count) ||
101        !ReadParam(m, iter, &typed_count) ||
102        !ReadParam(m, iter, &last_visit) ||
103        !ReadParam(m, iter, &hidden))
104      return false;
105    *p = ImporterURLRow(url);
106    p->title = title;
107    p->visit_count = visit_count;
108    p->typed_count = typed_count;
109    p->last_visit = last_visit;
110    p->hidden = hidden;
111    return true;
112  }
113  static void Log(const param_type& p, std::string* l) {
114    l->append("(");
115    LogParam(p.url, l);
116    l->append(", ");
117    LogParam(p.title, l);
118    l->append(", ");
119    LogParam(p.visit_count, l);
120    l->append(", ");
121    LogParam(p.typed_count, l);
122    l->append(", ");
123    LogParam(p.last_visit, l);
124    l->append(", ");
125    LogParam(p.hidden, l);
126    l->append(")");
127  }
128};  // ParamTraits<ImporterURLRow>
129
130// Traits for ImportedBookmarkEntry to pack/unpack.
131template <>
132struct ParamTraits<ImportedBookmarkEntry> {
133  typedef ImportedBookmarkEntry param_type;
134  static void Write(Message* m, const param_type& p) {
135    WriteParam(m, p.in_toolbar);
136    WriteParam(m, p.is_folder);
137    WriteParam(m, p.url);
138    WriteParam(m, p.path);
139    WriteParam(m, p.title);
140    WriteParam(m, p.creation_time);
141  }
142  static bool Read(const Message* m, PickleIterator* iter, param_type* p) {
143    return
144        (ReadParam(m, iter, &p->in_toolbar)) &&
145        (ReadParam(m, iter, &p->is_folder)) &&
146        (ReadParam(m, iter, &p->url)) &&
147        (ReadParam(m, iter, &p->path)) &&
148        (ReadParam(m, iter, &p->title)) &&
149        (ReadParam(m, iter, &p->creation_time));
150  }
151  static void Log(const param_type& p, std::string* l) {
152    l->append("(");
153    LogParam(p.in_toolbar, l);
154    l->append(", ");
155    LogParam(p.is_folder, l);
156    l->append(", ");
157    LogParam(p.url, l);
158    l->append(", ");
159    LogParam(p.path, l);
160    l->append(", ");
161    LogParam(p.title, l);
162    l->append(", ");
163    LogParam(p.creation_time, l);
164    l->append(")");
165  }
166};  // ParamTraits<ImportedBookmarkEntry>
167
168// Traits for ImportedFaviconUsage.
169template <>
170struct ParamTraits<ImportedFaviconUsage> {
171  typedef ImportedFaviconUsage param_type;
172  static void Write(Message* m, const param_type& p) {
173    WriteParam(m, p.favicon_url);
174    WriteParam(m, p.png_data);
175    WriteParam(m, p.urls);
176  }
177  static bool Read(const Message* m, PickleIterator* iter, param_type* p) {
178    return
179        ReadParam(m, iter, &p->favicon_url) &&
180        ReadParam(m, iter, &p->png_data) &&
181        ReadParam(m, iter, &p->urls);
182  }
183  static void Log(const param_type& p, std::string* l) {
184    l->append("(");
185    LogParam(p.favicon_url, l);
186    l->append(", ");
187    LogParam(p.png_data, l);
188    l->append(", ");
189    LogParam(p.urls, l);
190    l->append(")");
191  }
192};  // ParamTraits<ImportedFaviconUsage>
193
194// Traits for importer::URLKeywordInfo
195template <>
196struct ParamTraits<importer::URLKeywordInfo> {
197  typedef importer::URLKeywordInfo param_type;
198  static void Write(Message* m, const param_type& p) {
199    WriteParam(m, p.url);
200    WriteParam(m, p.keyword);
201    WriteParam(m, p.display_name);
202  }
203
204  static bool Read(const Message* m, PickleIterator* iter, param_type* p) {
205    return
206        ReadParam(m, iter, &p->url) &&
207        ReadParam(m, iter, &p->keyword) &&
208        ReadParam(m, iter, &p->display_name);
209  }
210
211  static void Log(const param_type& p, std::string* l) {
212    l->append("(");
213    LogParam(p.url, l);
214    l->append(", ");
215    LogParam(p.keyword, l);
216    l->append(", ");
217    LogParam(p.display_name, l);
218    l->append(")");
219  }
220};  // ParamTraits<importer::URLKeywordInfo>
221
222}  // namespace IPC
223
224#endif  // CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_MESSAGES_H_
225
226#define IPC_MESSAGE_START ProfileImportMsgStart
227
228//-----------------------------------------------------------------------------
229// ProfileImportProcess messages
230// These are messages sent from the browser to the profile import process.
231IPC_MESSAGE_CONTROL3(ProfileImportProcessMsg_StartImport,
232                     importer::SourceProfile,
233                     int                     /* Bitmask of items to import. */,
234                     DictionaryValue         /* Localized strings. */)
235
236IPC_MESSAGE_CONTROL0(ProfileImportProcessMsg_CancelImport)
237
238IPC_MESSAGE_CONTROL1(ProfileImportProcessMsg_ReportImportItemFinished,
239                     int  /* ImportItem */)
240
241//---------------------------------------------------------------------------
242// ProfileImportProcessHost messages
243// These are messages sent from the profile import process to the browser.
244// These messages send information about the status of the import and
245// individual import tasks.
246IPC_MESSAGE_CONTROL0(ProfileImportProcessHostMsg_Import_Started)
247
248IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_Import_Finished,
249                     bool         /* was import successful? */,
250                     std::string  /* error message, if any */)
251
252IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_ImportItem_Started,
253                     int  /* ImportItem */)
254
255IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_ImportItem_Finished,
256                     int  /* ImportItem */)
257
258// These messages send data from the external importer process back to
259// the process host so it can be written to the profile.
260IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHistoryImportStart,
261                     int  /* total number of ImporterURLRow items */)
262
263IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_NotifyHistoryImportGroup,
264                     std::vector<ImporterURLRow>,
265                     int  /* the source of URLs as in history::VisitSource.*/
266                          /* To simplify IPC call, pass as an integer */)
267
268IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHomePageImportReady,
269                     GURL  /* GURL of home page */)
270
271IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_NotifyBookmarksImportStart,
272                     string16  /* first folder name */,
273                     int       /* total number of bookmarks */)
274
275IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyBookmarksImportGroup,
276                     std::vector<ImportedBookmarkEntry>)
277
278IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFaviconsImportStart,
279                     int  /* total number of favicons */)
280
281IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFaviconsImportGroup,
282                     std::vector<ImportedFaviconUsage>)
283
284IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyPasswordFormReady,
285                     content::PasswordForm)
286
287IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_NotifyKeywordsReady,
288                     std::vector<importer::URLKeywordInfo>, // url_keywords
289                     bool  /* unique on host and path */)
290
291IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFirefoxSearchEngData,
292                     std::vector<std::string>) // search_engine_data
293
294