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

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

Issue 114923005: base: Discardable memory types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing include Created 7 years 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
OLDNEW
(Empty)
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 #include "base/memory/discardable_memory.h"
6
7 #include "base/lazy_instance.h"
8
9 namespace base {
10 namespace {
11
12 const struct {
13 const char* name;
14 DiscardableMemoryType type;
15 } kTypeNamePairs[] = {
16 { "android", DISCARDABLE_MEMORY_TYPE_ANDROID },
17 { "mac", DISCARDABLE_MEMORY_TYPE_MAC },
18 { "emulated", DISCARDABLE_MEMORY_TYPE_EMULATED }
19 };
20
21 struct TypeInitializedWithPreferredValue {
22 TypeInitializedWithPreferredValue() : value(DISCARDABLE_MEMORY_TYPE_NONE) {
23 std::vector<DiscardableMemoryType> supported_types;
24 DiscardableMemory::GetSupportedTypes(&supported_types);
25 DCHECK(!supported_types.empty());
26 value = supported_types[0];
27 }
28 DiscardableMemoryType value;
29 };
30 LazyInstance<TypeInitializedWithPreferredValue>::Leaky
31 g_discardable_memory_type = LAZY_INSTANCE_INITIALIZER;
32
33 } // namespace
34
35 // static
36 DiscardableMemoryType DiscardableMemory::GetNamedType(
37 const std::string& name) {
38 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTypeNamePairs); ++i) {
willchan no longer on Chromium 2013/12/24 01:21:06 I don't think you need to use the unsafe version o
reveman 2013/12/26 11:46:08 Done. After after giving the array type a name.
39 if (name == kTypeNamePairs[i].name)
40 return kTypeNamePairs[i].type;
41 }
42
43 return DISCARDABLE_MEMORY_TYPE_NONE;
44 }
45
46 // static
47 const char* DiscardableMemory::GetTypeName(DiscardableMemoryType type) {
48 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTypeNamePairs); ++i) {
willchan no longer on Chromium 2013/12/24 01:21:06 ditto...i think you can switch to arraysize()
reveman 2013/12/26 11:46:08 Done.
49 if (type == kTypeNamePairs[i].type)
50 return kTypeNamePairs[i].name;
51 }
52
53 return "unknown";
54 }
55
56 // static
57 void DiscardableMemory::SetType(DiscardableMemoryType type) {
58 g_discardable_memory_type.Get().value = type;
willchan no longer on Chromium 2013/12/24 01:21:06 This looks racy to me. If this is only allowed to
reveman 2013/12/26 11:46:08 Unit tests depend on being able to change this at
willchan no longer on Chromium 2013/12/26 18:25:54 Are there any valid reasons for non-test clients t
reveman 2013/12/26 21:53:35 Not at this point.
59 }
60
61 // static
62 DiscardableMemoryType DiscardableMemory::GetType() {
63 return g_discardable_memory_type.Get().value;
64 }
65
66 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698