summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer/importer_messages.h
blob: fd7b1dc86efb73edc17d4d2713ad57a1ae282b0f (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Copyright (c) 2010 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_MESSAGES_H_
#define CHROME_BROWSER_IMPORTER_IMPORTER_MESSAGES_H_
#pragma once

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/importer/importer_data_types.h"
#include "chrome/browser/importer/profile_writer.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/common/common_param_traits.h"
#include "ipc/ipc_message_utils.h"

namespace IPC {

// Traits for importer::ProfileInfo struct to pack/unpack.
template <>
struct ParamTraits<importer::ProfileInfo> {
  typedef importer::ProfileInfo param_type;
  static void Write(Message* m, const param_type& p) {
    WriteParam(m, p.description);
    WriteParam(m, static_cast<int>(p.browser_type));
    WriteParam(m, p.source_path);
    WriteParam(m, p.app_path);
    WriteParam(m, static_cast<int>(p.services_supported));
  }
  static bool Read(const Message* m, void** iter, param_type* p) {
    if (!ReadParam(m, iter, &p->description))
      return false;

    int browser_type = 0;
    if (!ReadParam(m, iter, &browser_type))
      return false;
    p->browser_type = static_cast<importer::ProfileType>(browser_type);

    if (!ReadParam(m, iter, &p->source_path) ||
        !ReadParam(m, iter, &p->app_path))
        return false;

    int services_supported = 0;
    if (!ReadParam(m, iter, &services_supported))
      return false;
    p->services_supported = static_cast<uint16>(services_supported);

    return true;
  }
  static void Log(const param_type& p, std::string* l) {
    l->append("(");
    LogParam(p.description, l);
    l->append(", ");
    LogParam(static_cast<int>(p.browser_type), l);
    l->append(", ");
    LogParam(p.source_path, l);
    l->append(", ");
    LogParam(p.app_path, l);
    l->append(", ");
    LogParam(static_cast<int>(p.services_supported), l);
    l->append(")");
  }
};  // ParamTraits<importer::ProfileInfo>

// Traits for history::URLRow to pack/unpack.
template <>
struct ParamTraits<history::URLRow> {
  typedef history::URLRow param_type;
  static void Write(Message* m, const param_type& p) {
    WriteParam(m, p.id());
    WriteParam(m, p.url());
    WriteParam(m, p.title());
    WriteParam(m, p.visit_count());
    WriteParam(m, p.typed_count());
    WriteParam(m, p.last_visit());
    WriteParam(m, p.hidden());
    WriteParam(m, p.favicon_id());
  }
  static bool Read(const Message* m, void** iter, param_type* p) {
    history::URLID id;
    GURL url;
    string16 title;
    int visit_count, typed_count;
    base::Time last_visit;
    bool hidden;
    history::FavIconID favicon_id;
    if (!ReadParam(m, iter, &id) ||
        !ReadParam(m, iter, &url) ||
        !ReadParam(m, iter, &title) ||
        !ReadParam(m, iter, &visit_count) ||
        !ReadParam(m, iter, &typed_count) ||
        !ReadParam(m, iter, &last_visit) ||
        !ReadParam(m, iter, &hidden) ||
        !ReadParam(m, iter, &favicon_id))
      return false;
    *p = history::URLRow(url, id);
    p->set_title(title);
    p->set_visit_count(visit_count);
    p->set_typed_count(typed_count);
    p->set_last_visit(last_visit);
    p->set_hidden(hidden);
    p->set_favicon_id(favicon_id);
    return true;
  }
  static void Log(const param_type& p, std::string* l) {
    l->append("(");
    LogParam(p.id(), l);
    l->append(", ");
    LogParam(p.url(), l);
    l->append(", ");
    LogParam(p.title(), l);
    l->append(", ");
    LogParam(p.visit_count(), l);
    l->append(", ");
    LogParam(p.typed_count(), l);
    l->append(", ");
    LogParam(p.last_visit(), l);
    l->append(", ");
    LogParam(p.hidden(), l);
    l->append(", ");
    LogParam(p.favicon_id(), l);
    l->append(")");
  }
};  // ParamTraits<history::URLRow>

// Traits for ProfileWriter::BookmarkEntry to pack/unpack.
template <>
struct ParamTraits<ProfileWriter::BookmarkEntry> {
  typedef ProfileWriter::BookmarkEntry param_type;
  static void Write(Message* m, const param_type& p) {
    WriteParam(m, p.in_toolbar);
    WriteParam(m, p.url);
    WriteParam(m, p.path);
    WriteParam(m, p.title);
    WriteParam(m, p.creation_time);
  }
  static bool Read(const Message* m, void** iter, param_type* p) {
    return
        (ReadParam(m, iter, &p->in_toolbar)) &&
        (ReadParam(m, iter, &p->url)) &&
        (ReadParam(m, iter, &p->path)) &&
        (ReadParam(m, iter, &p->title)) &&
        (ReadParam(m, iter, &p->creation_time));
  }
  static void Log(const param_type& p, std::string* l) {
    l->append("(");
    LogParam(p.in_toolbar, l);
    l->append(", ");
    LogParam(p.url, l);
    l->append(", ");
    LogParam(p.path, l);
    l->append(", ");
    LogParam(p.title, l);
    l->append(", ");
    LogParam(p.creation_time, l);
    l->append(")");
  }
};  // ParamTraits<ProfileWriter::BookmarkEntry>

// Traits for history::ImportedFavIconUsage.
template <>
struct ParamTraits<history::ImportedFavIconUsage> {
  typedef history::ImportedFavIconUsage param_type;
  static void Write(Message* m, const param_type& p) {
    WriteParam(m, p.favicon_url);
    WriteParam(m, p.png_data);
    WriteParam(m, p.urls);
  }
  static bool Read(const Message* m, void** iter, param_type* p) {
    return
        ReadParam(m, iter, &p->favicon_url) &&
        ReadParam(m, iter, &p->png_data) &&
        ReadParam(m, iter, &p->urls);
  }
  static void Log(const param_type& p, std::string* l) {
    l->append("(");
    LogParam(p.favicon_url, l);
    l->append(", ");
    LogParam(p.png_data, l);
    l->append(", ");
    LogParam(p.urls, l);
    l->append(")");
  }
};  // ParamTraits<history::ImportedFavIconUsage

// Traits for TemplateURLRef
template <>
struct ParamTraits<TemplateURLRef> {
  typedef TemplateURLRef param_type;
  static void Write(Message* m, const param_type& p) {
    WriteParam(m, p.url());
    WriteParam(m, p.index_offset());
    WriteParam(m, p.page_offset());
  }
  static bool Read(const Message* m, void** iter, param_type* p) {
    std::string url;
    int index_offset;
    int page_offset;
    if (!ReadParam(m, iter, &url) ||
        !ReadParam(m, iter, &index_offset) ||
        !ReadParam(m, iter, &page_offset))
      return false;
    *p = TemplateURLRef(url, index_offset, page_offset);
    return true;
  }
  static void Log(const param_type& p, std::string* l) {
    l->append("<TemplateURLRef>");
  }
};

// Traits for TemplateURL::ImageRef
template <>
struct ParamTraits<TemplateURL::ImageRef> {
  typedef TemplateURL::ImageRef param_type;
  static void Write(Message* m, const param_type& p) {
    WriteParam(m, p.type);
    WriteParam(m, p.width);
    WriteParam(m, p.height);
    WriteParam(m, p.url);
  }
  static bool Read(const Message* m, void** iter, param_type* p) {
    std::wstring type;
    int width;
    int height;
    GURL url;
    if (!ReadParam(m, iter, &type) ||
        !ReadParam(m, iter, &width) ||
        !ReadParam(m, iter, &height) ||
        !ReadParam(m, iter, &url))
      return false;
    *p = TemplateURL::ImageRef(type, width, height, url);  // here in
    return true;
  }
  static void Log(const param_type& p, std::string* l) {
    l->append("<TemplateURL::ImageRef>");
  }
};

// Traits for TemplateURL
template <>
struct ParamTraits<TemplateURL> {
  typedef TemplateURL param_type;
  static void Write(Message* m, const param_type& p) {
    WriteParam(m, p.short_name());
    WriteParam(m, p.description());
    if (p.suggestions_url()) {
      WriteParam(m, true);
      WriteParam(m, *p.suggestions_url());
    } else {
      WriteParam(m, false);
    }
    WriteParam(m, *p.url());
    WriteParam(m, p.originating_url());
    WriteParam(m, p.keyword());
    WriteParam(m, p.autogenerate_keyword());
    WriteParam(m, p.show_in_default_list());
    WriteParam(m, p.safe_for_autoreplace());
    WriteParam(m, p.image_refs().size());

    std::vector<TemplateURL::ImageRef>::const_iterator iter;
    for (iter = p.image_refs().begin(); iter != p.image_refs().end(); ++iter) {
      WriteParam(m, iter->type);
      WriteParam(m, iter->width);
      WriteParam(m, iter->height);
      WriteParam(m, iter->url);
    }

    WriteParam(m, p.languages());
    WriteParam(m, p.input_encodings());
    WriteParam(m, p.date_created());
    WriteParam(m, p.usage_count());
    WriteParam(m, p.prepopulate_id());
  }
  static bool Read(const Message* m, void** iter, param_type* p) {
    std::wstring short_name;
    std::wstring description;
    bool includes_suggestions_url;
    TemplateURLRef suggestions_url;
    TemplateURLRef url;
    GURL originating_url;
    std::wstring keyword;
    bool autogenerate_keyword;
    bool show_in_default_list;
    bool safe_for_autoreplace;
    std::vector<std::wstring> languages;
    std::vector<std::string> input_encodings;
    base::Time date_created;
    int usage_count;
    int prepopulate_id;

    if (!ReadParam(m, iter, &short_name) ||
        !ReadParam(m, iter, &description))
      return false;

    if (!ReadParam(m, iter, &includes_suggestions_url))
      return false;
    if (includes_suggestions_url) {
        if (!ReadParam(m, iter, &suggestions_url))
          return false;
    }

    size_t image_refs_size = 0;
    if (!ReadParam(m, iter, &url) ||
        !ReadParam(m, iter, &originating_url) ||
        !ReadParam(m, iter, &keyword) ||
        !ReadParam(m, iter, &autogenerate_keyword) ||
        !ReadParam(m, iter, &show_in_default_list) ||
        !ReadParam(m, iter, &safe_for_autoreplace) ||
        !ReadParam(m, iter, &image_refs_size))
      return false;

    *p = TemplateURL();
    for (size_t i = 0; i < image_refs_size; ++i) {
      std::wstring type;
      int width;
      int height;
      GURL url;
      if (!ReadParam(m, iter, &type) ||
          !ReadParam(m, iter, &width) ||
          !ReadParam(m, iter, &height) ||
          !ReadParam(m, iter, &url))
        return false;
      p->add_image_ref(TemplateURL::ImageRef(type, width, height, url));
    }

    if (!ReadParam(m, iter, &languages) ||
        !ReadParam(m, iter, &input_encodings) ||
        !ReadParam(m, iter, &date_created) ||
        !ReadParam(m, iter, &usage_count) ||
        !ReadParam(m, iter, &prepopulate_id))
      return false;

    p->set_short_name(short_name);
    p->set_description(description);
    p->SetSuggestionsURL(suggestions_url.url(), suggestions_url.index_offset(),
                         suggestions_url.page_offset());
    p->SetURL(url.url(), url.index_offset(), url.page_offset());
    p->set_originating_url(originating_url);
    p->set_keyword(keyword);
    p->set_autogenerate_keyword(autogenerate_keyword);
    p->set_show_in_default_list(show_in_default_list);
    p->set_safe_for_autoreplace(safe_for_autoreplace);

    std::vector<std::wstring>::const_iterator lang_iter;
    for (lang_iter = languages.begin();
         lang_iter != languages.end();
         ++lang_iter) {
      p->add_language(*lang_iter);
    }
    p->set_input_encodings(input_encodings);
    p->set_date_created(date_created);
    p->set_usage_count(usage_count);
    p->set_prepopulate_id(prepopulate_id);
    return true;
  }
  static void Log(const param_type& p, std::string* l) {
    l->append("<TemplateURL>");
  }
};

}  // namespace IPC

#define MESSAGES_INTERNAL_FILE \
    "chrome/browser/importer/importer_messages_internal.h"
#include "ipc/ipc_message_macros.h"

#endif  // CHROME_BROWSER_IMPORTER_IMPORTER_MESSAGES_H_