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