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

Side by Side Diff: base/memory/discardable_memory.cc

Issue 1013463003: Update from https://crrev.com/320931 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « base/memory/discardable_memory.h ('k') | base/memory/discardable_memory_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/discardable_memory.h" 5 #include "base/memory/discardable_memory.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/memory/discardable_memory_shmem.h"
8 #include "base/logging.h"
9 8
10 namespace base { 9 namespace base {
11 namespace {
12
13 const struct TypeNamePair {
14 DiscardableMemoryType type;
15 const char* name;
16 } kTypeNamePairs[] = {
17 { DISCARDABLE_MEMORY_TYPE_SHMEM, "shmem" }
18 };
19
20 DiscardableMemoryType g_preferred_type = DISCARDABLE_MEMORY_TYPE_NONE;
21
22 struct DefaultPreferredType {
23 DefaultPreferredType() : value(DISCARDABLE_MEMORY_TYPE_NONE) {
24 std::vector<DiscardableMemoryType> supported_types;
25 DiscardableMemory::GetSupportedTypes(&supported_types);
26 DCHECK(!supported_types.empty());
27 value = supported_types[0];
28 }
29 DiscardableMemoryType value;
30 };
31 LazyInstance<DefaultPreferredType>::Leaky g_default_preferred_type =
32 LAZY_INSTANCE_INITIALIZER;
33
34 } // namespace
35
36 // static
37 DiscardableMemoryType DiscardableMemory::GetNamedType(
38 const std::string& name) {
39 for (size_t i = 0; i < arraysize(kTypeNamePairs); ++i) {
40 if (name == kTypeNamePairs[i].name)
41 return kTypeNamePairs[i].type;
42 }
43
44 return DISCARDABLE_MEMORY_TYPE_NONE;
45 }
46
47 // static
48 const char* DiscardableMemory::GetTypeName(DiscardableMemoryType type) {
49 for (size_t i = 0; i < arraysize(kTypeNamePairs); ++i) {
50 if (type == kTypeNamePairs[i].type)
51 return kTypeNamePairs[i].name;
52 }
53
54 return "unknown";
55 }
56
57 // static
58 void DiscardableMemory::SetPreferredType(DiscardableMemoryType type) {
59 // NONE is a reserved value and not a valid default type.
60 DCHECK_NE(DISCARDABLE_MEMORY_TYPE_NONE, type);
61
62 // Make sure this function is only called once before the first call
63 // to GetPreferredType().
64 DCHECK_EQ(DISCARDABLE_MEMORY_TYPE_NONE, g_preferred_type);
65
66 g_preferred_type = type;
67 }
68
69 // static
70 DiscardableMemoryType DiscardableMemory::GetPreferredType() {
71 if (g_preferred_type == DISCARDABLE_MEMORY_TYPE_NONE)
72 g_preferred_type = g_default_preferred_type.Get().value;
73
74 return g_preferred_type;
75 }
76 10
77 // static 11 // static
78 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemory( 12 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemory(
79 size_t size) { 13 size_t size) {
80 return CreateLockedMemoryWithType(GetPreferredType(), size); 14 return make_scoped_ptr(new internal::DiscardableMemoryShmem(size));
81 } 15 }
82 16
83 } // namespace base 17 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory.h ('k') | base/memory/discardable_memory_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698