summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/window_restore_utils.mm
blob: 133fa29db1377b68d58dc34df7cb7282e263285f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "chrome/browser/ui/cocoa/window_restore_utils.h"

#import <Foundation/Foundation.h>

#include "base/mac/mac_util.h"

namespace restore_utils {

bool IsWindowRestoreEnabled() {
  if (!base::mac::IsOSLionOrLater())
    return false;

  NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  // The defaults must be synchronized here otherwise a stale value will be
  // returned for an indeterminate amount of time.
  [defaults synchronize];

  // By default, the preference is not set. When it's not, the intrinsic Lion
  // default (YES) should be returned.
  NSDictionary* prefs = [defaults dictionaryRepresentation];
  NSNumber* value = [prefs objectForKey:@"NSQuitAlwaysKeepsWindows"];
  if (!value)
    return true;

  return !![value boolValue];
}

}  // namespace restore_utils