~osomon/oxide/non-ime-initiated-text-edit

« back to all changes in this revision

Viewing changes to shared/browser/permissions/oxide_temporary_saved_permission_context.cc

  • Committer: Olivier Tilloy
  • Date: 2015-06-15 14:13:07 UTC
  • mfrom: (1022.1.110 oxide)
  • Revision ID: olivier.tilloy@canonical.com-20150615141307-db9q44mc5wduuot0
Merge the latest changes from trunk and resolve a conflict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2015 Canonical Ltd.
 
3
 
 
4
// This library is free software; you can redistribute it and/or
 
5
// modify it under the terms of the GNU Lesser General Public
 
6
// License as published by the Free Software Foundation; either
 
7
// version 2.1 of the License, or (at your option) any later version.
 
8
 
 
9
// This library is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
// Lesser General Public License for more details.
 
13
 
 
14
// You should have received a copy of the GNU Lesser General Public
 
15
// License along with this library; if not, write to the Free Software
 
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
#include "oxide_temporary_saved_permission_context.h"
 
19
 
 
20
namespace oxide {
 
21
 
 
22
TemporarySavedPermissionContext::TemporarySavedPermissionContext() {}
 
23
 
 
24
TemporarySavedPermissionContext::~TemporarySavedPermissionContext() {}
 
25
 
 
26
TemporarySavedPermissionStatus
 
27
TemporarySavedPermissionContext::GetPermissionStatus(
 
28
    TemporarySavedPermissionType type,
 
29
    const GURL& primary_url,
 
30
    const GURL& secondary_url) {
 
31
  Key key = std::make_pair(primary_url, secondary_url);
 
32
 
 
33
  base::AutoLock lock(lock_);
 
34
 
 
35
  Map& map = maps_[type];
 
36
  const auto& it = map.find(key);
 
37
  if (it == map.end()) {
 
38
    return TEMPORARY_SAVED_PERMISSION_STATUS_ASK;
 
39
  }
 
40
 
 
41
  return it->second;
 
42
}
 
43
 
 
44
void TemporarySavedPermissionContext::SetPermissionStatus(
 
45
    TemporarySavedPermissionType type,
 
46
    const GURL& primary_url,
 
47
    const GURL& secondary_url,
 
48
    TemporarySavedPermissionStatus status) {
 
49
  Key key = std::make_pair(primary_url, secondary_url);
 
50
 
 
51
  base::AutoLock lock(lock_);
 
52
 
 
53
  Map& map = maps_[type];
 
54
  if (status == TEMPORARY_SAVED_PERMISSION_STATUS_ASK) {
 
55
    map.erase(key);
 
56
    return;
 
57
  }
 
58
 
 
59
  map[key] = status;
 
60
}
 
61
 
 
62
void TemporarySavedPermissionContext::Clear() {
 
63
  base::AutoLock lock(lock_);
 
64
  for (int i = PERMISSION_TYPES_START; i < NUM_PERMISSION_TYPES; ++i) {
 
65
    maps_[i].clear();
 
66
  }
 
67
}
 
68
 
 
69
} // namespace oxide