Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Side by Side Diff: content/common/url_schemes.cc

Issue 10383298: Move RegisterContentSchemes from public url_constants into non-public url_schemes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: allow content/common/savable_url_schemes.h to be included by url_constants.cc Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/url_schemes.h ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "content/common/url_schemes.h"
6
7 #include <string.h>
8
9 #include <algorithm>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/string_util.h"
15 #include "content/common/savable_url_schemes.h"
16 #include "content/public/common/content_client.h"
17 #include "content/public/common/url_constants.h"
18 #include "googleurl/src/url_util.h"
19
20 namespace {
21
22 void AddStandardSchemeHelper(const std::string& scheme) {
23 url_util::AddStandardScheme(scheme.c_str());
24 }
25
26 } // namespace
27
28 namespace content {
29
30 void RegisterContentSchemes(bool lock_standard_schemes) {
31 std::vector<std::string> additional_standard_schemes;
32 std::vector<std::string> additional_savable_schemes;
33 GetContentClient()->AddAdditionalSchemes(
34 &additional_standard_schemes,
35 &additional_savable_schemes);
36
37 // Don't need "chrome-internal" which was used in old versions of Chrome for
38 // the new tab page.
39 url_util::AddStandardScheme(chrome::kChromeDevToolsScheme);
40 url_util::AddStandardScheme(chrome::kChromeUIScheme);
41 url_util::AddStandardScheme(chrome::kMetadataScheme);
42 std::for_each(additional_standard_schemes.begin(),
43 additional_standard_schemes.end(),
44 AddStandardSchemeHelper);
45
46 // Prevent future modification of the standard schemes list. This is to
47 // prevent accidental creation of data races in the program. AddStandardScheme
48 // isn't threadsafe so must be called when GURL isn't used on any other
49 // thread. This is really easy to mess up, so we say that all calls to
50 // AddStandardScheme in Chrome must be inside this function.
51 if (lock_standard_schemes)
52 url_util::LockStandardSchemes();
53
54 // We rely on the above lock to protect this part from being invoked twice.
55 if (!additional_savable_schemes.empty()) {
56 const char* const* default_schemes = GetSavableSchemesInternal();
57 const char* const* default_schemes_end = NULL;
58 for (default_schemes_end = default_schemes; *default_schemes_end;
59 ++default_schemes_end) {}
60 const int default_schemes_count = default_schemes_end - default_schemes;
61
62 int schemes = static_cast<int>(additional_savable_schemes.size());
63 // The array, and the copied schemes won't be freed, but will remain
64 // reachable.
65 char **savable_schemes = new char*[schemes + default_schemes_count + 1];
66 memcpy(savable_schemes,
67 default_schemes,
68 default_schemes_count * sizeof(default_schemes[0]));
69 for (int i = 0; i < schemes; ++i) {
70 savable_schemes[default_schemes_count + i] =
71 base::strdup(additional_savable_schemes[i].c_str());
72 }
73 savable_schemes[default_schemes_count + schemes] = 0;
74
75 SetSavableSchemes(savable_schemes);
76 }
77 }
78
79 } // namespace content
OLDNEW
« no previous file with comments | « content/common/url_schemes.h ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698