closure: fix compile error by adding missing externs
[chromium-blink-merge.git] / components / bookmarks / browser / bookmark_node_data_views.cc
blob809113d0b7786026f6b4af16e2d6fbf2450ac0c8
1 // Copyright 2014 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.
5 #include "components/bookmarks/browser/bookmark_node_data.h"
7 #include "base/logging.h"
8 #include "base/pickle.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/base/clipboard/clipboard.h"
11 #include "url/url_constants.h"
13 namespace bookmarks {
15 // static
16 const ui::OSExchangeData::CustomFormat&
17 BookmarkNodeData::GetBookmarkCustomFormat() {
18 CR_DEFINE_STATIC_LOCAL(
19 ui::OSExchangeData::CustomFormat,
20 format,
21 (ui::Clipboard::GetFormatType(BookmarkNodeData::kClipboardFormatString)));
23 return format;
26 void BookmarkNodeData::Write(const base::FilePath& profile_path,
27 ui::OSExchangeData* data) const {
28 DCHECK(data);
30 // If there is only one element and it is a URL, write the URL to the
31 // clipboard.
32 if (has_single_url()) {
33 if (elements[0].url.SchemeIs(url::kJavaScriptScheme)) {
34 data->SetString(base::UTF8ToUTF16(elements[0].url.spec()));
35 } else {
36 data->SetURL(elements[0].url, elements[0].title);
40 Pickle data_pickle;
41 WriteToPickle(profile_path, &data_pickle);
43 data->SetPickledData(GetBookmarkCustomFormat(), data_pickle);
46 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) {
47 elements.clear();
49 profile_path_.clear();
51 if (data.HasCustomFormat(GetBookmarkCustomFormat())) {
52 Pickle drag_data_pickle;
53 if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) {
54 if (!ReadFromPickle(&drag_data_pickle))
55 return false;
57 } else {
58 // See if there is a URL on the clipboard.
59 GURL url;
60 base::string16 title;
61 if (data.GetURLAndTitle(
62 ui::OSExchangeData::CONVERT_FILENAMES, &url, &title))
63 ReadFromTuple(url, title);
66 return is_valid();
69 } // namespace bookmarks